private void CreatePostslist(string xml, string page_name) { try { int cnt = 0; mypost p; List<mypost> myposts = new List<mypost>(); Dictionary<string, string> posts_dict = new Dictionary<string, string>(); var jsonDat = (JObject.Parse(xml)); foreach (var key in jsonDat) { if (key.Key.Equals("statuses")) { for (int x = 0; x < key.Value.Count(); x++) { if (!posts_dict.ContainsKey(Convert.ToString(key.Value[x]["id"]))) { posts_dict.Add(Convert.ToString(key.Value[x]["id"]), Convert.ToString(key.Value[x]["text"])); p = new mypost(); p.post = Convert.ToString(key.Value[x]["text"]); p.post_id = Convert.ToString(key.Value[x]["id"]); p.created_on = ""; p.post_url = "https://twitter.com/" + page_name + "/status/" + p.post_id; if (Convert.ToString(key.Value[x]["entities"]["media"]) != "") { p.img_url = Convert.ToString(key.Value[x]["entities"]["media"][0]["media_url"]); } else { p.img_url = ""; } myposts.Add(p); cnt++; } if (cnt > 10) break; } } } if (cnt == 0) { p = new mypost(); p.post = "No recent posts found"; p.post_id = "0"; p.created_on = ""; p.img_url = ""; myposts.Add(p); } rep_PagePosts2.DataSource = myposts; rep_PagePosts2.DataBind(); } catch (Exception ex) { Panel2_Clear(); lblPagePostsMsg2.Text = " Error Parsing the result "; lblPagePostsMsg2.Visible = true; } }
private void LoadFBPosts(String page_url) { var start = page_url.LastIndexOf("/") + 1; var end = page_url.Length; String page_url1 = page_url.Substring(start, end - start); Panel2_Clear(); try { var accessToken = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["FB_access_token"]); var client = new FacebookClient(accessToken); dynamic posts; posts = client.Get("/" + page_url1 + "/posts"); int cnt = 0; mypost p; List<mypost> myposts = new List<mypost>(); //Loop through the returned friends foreach (var i in posts["data"]) { p = new mypost(); foreach (var j in i["actions"]) { p.post_url = j["link"]; break; } if (i["type"] == "photo") { p.post_id = i["object_id"]; p.img_url = (i.ContainsKey("picture")) ? i["picture"] : ""; } else { string post_id_string= Convert.ToString(i["id"]); p.post_id = post_id_string.Split('_')[1]; } if (i.ContainsKey("message")) { p.post = i["message"].Substring(0, ((i["message"].Length < 200) ? i["message"].Length : 200)); p.img_url = (i.ContainsKey("picture")) ? i["picture"] : ""; } p.created_on = i["created_time"]; myposts.Add(p); cnt++; if (cnt > 10) break; } rep_PagePosts2.DataSource = myposts; rep_PagePosts2.DataBind(); hiddenPageURL2.Value = page_url; } catch (Exception ex) { Panel2_Clear(); lblPagePostsMsg2.Text = " Not a valid Page URL "; lblPagePostsMsg2.Visible = true; } }