SetJsonSerializers() private method

private SetJsonSerializers ( string>.Func jsonSerializer, Func jsonDeserializer ) : void
jsonSerializer string>.Func
jsonDeserializer Func
return void
 /// <summary>
 /// Creates a <see cref="FacebookClient"/> with AppId and AppSecret that uses Json.NET for serialization and deserialization.
 /// </summary>
 /// <returns>The <see cref="FacebookClient"/> instance.</returns>
 public virtual FacebookClient CreateClient()
 {
     FacebookClient client = new FacebookClient();
     client.AppId = _config.AppId;
     client.AppSecret = _config.AppSecret;
     client.SetJsonSerializers(JsonConvert.SerializeObject, JsonConvert.DeserializeObject);
     return client;
 }
Ejemplo n.º 2
0
        private bool GetWebPosts()
        {
            _entities = new List<PostEntity>();
            using (var browser = new Browser())
            {
                try
                {
                    var redirectUrl = "http://www.mercenary.hu";
                    var clientID = "465962063448465";
                    var scope = "user_posts";
                    var navigationUrl = $"https://graph.facebook.com/oauth/authorize?client_id={clientID}&redirect_uri={redirectUrl}&scope={scope}&type=user_agent&display=popup";
                    browser.Open(navigationUrl);
                    var home = ModelFactory.GetModel<HomePage>();
                    home.Email = ConfigurationManager.AppSettings["UserEmail"];
                    home.Pass = ConfigurationManager.AppSettings["UserPass"];
                    home.Login();

                    var r = new Regex(@"#access_token=(.*)&expires_in=(.*)");
                    var accessToken = r.Match(browser.Uri.Fragment).Groups[1].Value;
                    _client = new FacebookClient(accessToken);
                    _client.SetJsonSerializers(JsonConvert.SerializeObject, JsonConvert.DeserializeObject);

                    //browser.Open("http://www.facebook.com/login.php");
                    //var home = ModelFactory.GetModel<HomePage>();
                    //home.Email = ConfigurationManager.AppSettings["UserEmail"];
                    //home.Pass = ConfigurationManager.AppSettings["UserPass"];
                    //home.Login();

                    var date = new DateTime(ToDate.Year, ToDate.Month, 1).AddMonths(1);
                    var userId = ConfigurationManager.AppSettings["UserId"];
                    do
                    {
                        date = date.AddMonths(-1);
                        browser.Open($"http://www.facebook.com/{userId}/timeline/{date.Year}/{date.Month}");
                        var timeline = ModelFactory.GetModel<TimelinePage>();
                        var c = timeline.PostCount;
                        bool changes;
                        do
                        {
                            var nc = c;
                            Context.Driver.ExecuteScript("window.scrollTo(0,document.body.scrollHeight);");
                            for (var i = 0; i < 5; i++)
                            {
                                Thread.Sleep(100);
                                nc = timeline.PostCount;
                                Debug.WriteLine("{0} {1} {2}", DateTime.Now, c, nc);
                                if (c != nc) break;
                            }
                            changes = c != nc;
                            c = nc;
                        } while (changes);

                        if (c == 0) continue;

                        foreach (var id in timeline.Posts.Select(p => p.TopLevelObjectId).Where(id => id != 0))
                        {
                            _workHandler.Run(() => GetPostDetails(id), GetPostDetailsCallback);
                        }
                    }
                    while (date > FromDate);
                }
                catch
                {
                    browser.SaveArtifacts();
                }
            }
            return true;
        }