// methode om posts in de lijst posts te plaatsen van alle sociale netwerken public void syncPosts() { if ((this.chkbFacebook.Checked || this.chkBoxAll.Checked) && currentParent.loggedInUsers.ContainsKey(Post.SocialNetwork.Facebook)) { // sync Facebook: http://facebooksdk.net/docs/making-asynchronous-requests/ // parameters om mee te geven aan het request naar de FB API Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters["since"] = this.FBsince; parameters["limit"] = 25; // news feed ophalen if (!FBisSyncing) { this.FBisSyncing = true; currentParent.FBclient.GetTaskAsync("/me/home", parameters); currentParent.FBclient.GetCompleted += (o, e) => { if (e.Error == null) { dynamic result = e.GetResultData(); if (result.paging != null && result.data.Count != 0) { // nodig om bij te houden van wanneer we de laatste resultaten hebben opgehaald (Google: Facebook API pagination) string prevLink = result.paging.previous; string since = prevLink.Substring(prevLink.LastIndexOf("&since=") + 7, prevLink.IndexOf("&access_token=") - (prevLink.LastIndexOf("&since=") + 7)); this.FBsince = Convert.ToInt32(since); // de opgehaalde posts verwerken foreach (dynamic fbPost in result.data) { string strFromID = fbPost.from.id; long intFromID = Convert.ToInt64(strFromID); User user = new FacebookUser(intFromID.ToString(), fbPost.from.name, "http://graph.facebook.com/" + strFromID + "/picture?width=100&height=100"); string bericht = fbPost.message; string link = fbPost.link; string id = fbPost.id; string pictureUrl = fbPost.picture; DateTime tijdstip = Post.parseFBTime((string)fbPost.created_time); Post postToAdd; if (fbPost.type == "photo") { postToAdd = new FotoPost(id, user, bericht + " " + link, tijdstip, Post.SocialNetwork.Facebook, pictureUrl); } else { postToAdd = new Post(id, user, bericht + " " + link, tijdstip, Post.SocialNetwork.Facebook); } this.addPost(postToAdd); } } } this.FBisSyncing = false; }; } } if ((this.chkbInstagram.Checked || this.chkBoxAll.Checked) && currentParent.loggedInUsers.ContainsKey(Post.SocialNetwork.Instagram)) { // sync Instagram } if ((this.chkbTumblr.Checked || this.chkBoxAll.Checked) && currentParent.loggedInUsers.ContainsKey(Post.SocialNetwork.Tumblr)) { // sync Tumblr } if ((this.chkbTwitter.Checked || this.chkBoxAll.Checked) && currentParent.loggedInUsers.ContainsKey(Post.SocialNetwork.Twitter)) { if (!TWisSyncing) { TWisSyncing = true; ListTweetsOnHomeTimelineOptions options = new ListTweetsOnHomeTimelineOptions(); if (TWsince != -1) options.SinceId = TWsince; else options.Count = 10; IAsyncResult result = currentParent.TWclient.ListTweetsOnHomeTimeline(options, (tweets, response) => { if (response.StatusCode == HttpStatusCode.OK) { foreach (TwitterStatus tweet in tweets) { if (tweet.Id > TWsince) TWsince = tweet.Id; User user = new TwitterUser(tweet.Author.ScreenName, tweet.Author.ScreenName, tweet.Author.ProfileImageUrl); string bericht = tweet.Text; string id = tweet.IdStr; string link = tweet.Source; DateTime tijdstip = Post.parseTWTime(tweet.CreatedDate.ToString()); Post postToAdd = new Post(id, user, bericht, tijdstip, Post.SocialNetwork.Twitter); foreach (TwitterMedia media in tweet.Entities.Media) { if (media.MediaType == TwitterMediaType.Photo) { postToAdd = new FotoPost(id, user, bericht, tijdstip, Post.SocialNetwork.Twitter, media.MediaUrl); } } this.addPost(postToAdd); } } this.TWisSyncing = false; }); } } this.showPosts(); }
public FotoPost(string id, User user, string inhoud, DateTime tijdstip, Post.SocialNetwork type, string fotoURL) : base(id, user, inhoud, tijdstip, type) { this.fotoUrl = fotoURL; }
private void addPost(Post newPost) { posts.Add(newPost); posts.Sort(); }