public void RefreshFBFeed() { WebRequest request = WebRequest.Create("https://graph.facebook.com/CMSXiaoYaoPai/feed?fields=full_picture,picture,message,created_time,comments{comment_count},likes,link,name,admin_creator,description,caption&limit=10&access_token=" + FBAccessToken); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream, Encoding.UTF8); String responseString = reader.ReadToEnd(); feeds = JsonConvert.DeserializeObject <FacebookFeeds>(responseString); Session["FBFeed"] = feeds; int i = 0; foreach (FacebookFeed FBFeed in feeds.data) { i++; String attachedImg = FBFeed.Picture; String message = FBFeed.Message; String time = FBFeed.Created_time; String link = FBFeed.Link; String linkName = FBFeed.Name; HtmlGenericControl msg = (HtmlGenericControl)fbLiveFeed.FindControl("pmsg" + (i.ToString())); msg.InnerText = message; HtmlGenericControl pmeta = (HtmlGenericControl)fbLiveFeed.FindControl("pmeta" + (i.ToString())); DateTime dt = Convert.ToDateTime(FBFeed.Created_time); pmeta.InnerHtml = ToRelativeTimeString(dt) + " "; } response.Close(); }
private void RefreshSocialFeed() { if (Session["FBFeed"] != null) { FacebookFeeds feeds2 = Session["FBFeed"] as FacebookFeeds; WebRequest request = WebRequest.Create("https://graph.facebook.com/CMSXiaoYaoPai/feed?fields=full_picture,picture,message,created_time,comments{comment_count},likes,link,name,admin_creator,description,caption&limit=10&access_token=" + FBAccessToken); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream, Encoding.UTF8); String responseString = reader.ReadToEnd(); FacebookFeeds newFeeds = JsonConvert.DeserializeObject <FacebookFeeds>(responseString); Session["FBFeed2"] = newFeeds; if (feeds2.data[0].Created_time != newFeeds.data[0].Created_time) { LookForNewFBFeed(); } } }
private void LookForNewFBFeed() { System.Windows.Forms.MessageBox.Show("Got new!"); FacebookFeeds oldfeeds = Session["FBFeed"] as FacebookFeeds; FacebookFeeds newfeeds = Session["FBFeed2"] as FacebookFeeds; foreach (FacebookFeed FBFeed in newfeeds.data) { //Session["FBFeed"] = newfeeds; String attachedImg = FBFeed.Picture; String message = FBFeed.Message; String time = FBFeed.Created_time; String link = FBFeed.Link; String linkName = FBFeed.Name; if (oldfeeds.data[0].Created_time != time) { HtmlGenericControl mainDiv = new HtmlGenericControl("li"); HtmlGenericControl postUserImg = new HtmlGenericControl("img"); HtmlGenericControl divStatus = new HtmlGenericControl("div"); HtmlGenericControl p = new HtmlGenericControl("p"); HtmlGenericControl divLink = new HtmlGenericControl("div"); HtmlGenericControl attachImg = new HtmlGenericControl("img"); HtmlGenericControl commentsP = new HtmlGenericControl("p"); HtmlGenericControl divAttach = new HtmlGenericControl("div"); HtmlGenericControl attachPname = new HtmlGenericControl("p"); HtmlGenericControl attachPdesc = new HtmlGenericControl("p"); HtmlAnchor attachAHREF = new HtmlAnchor(); HtmlAnchor imgAHREF = new HtmlAnchor(); divStatus.Attributes.Add("class", "status"); p.Attributes.Add("class", "message"); p.InnerHtml = message; divStatus.Controls.Add(p); if ((link != null) && (link != String.Empty)) { divLink.Attributes.Add("class", "attachment"); if (attachedImg != "") { attachImg.Attributes["src"] = attachedImg; attachImg.Attributes.Add("class", "picture"); imgAHREF.Controls.Add(attachImg); imgAHREF.Attributes["href"] = link; imgAHREF.Attributes["target"] = "_blank"; } divAttach.Attributes.Add("class", "attachment-data"); attachPname.Attributes.Add("class", "name"); attachPdesc.Attributes.Add("class", "description"); attachPdesc.InnerText = FBFeed.Description; attachAHREF.Attributes["href"] = link; attachAHREF.Attributes["target"] = "_blank"; attachAHREF.InnerText = linkName; divLink.Controls.Add(imgAHREF); attachPname.Controls.Add(attachAHREF); divLink.Controls.Add(attachPname); divLink.Controls.Add(attachPdesc); divLink.Controls.Add(divAttach); divStatus.Controls.Add(divLink); } commentsP.Attributes.Add("class", "meta"); DateTime dt = Convert.ToDateTime(FBFeed.Created_time); commentsP.InnerHtml += ToRelativeTimeString(dt) + " "; mainDiv.Controls.Add(divStatus); mainDiv.Controls.Add(commentsP); fbLiveFeed.Controls.Add(mainDiv); } } }
private void RefreshFBFeed() { WebRequest request = WebRequest.Create("https://graph.facebook.com/CMSXiaoYaoPai/feed?fields=full_picture,picture,message,created_time,comments{comment_count},likes,link,name,admin_creator,description,caption&limit=10&access_token=" + FBAccessToken); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream, Encoding.UTF8); String responseString = reader.ReadToEnd(); feeds = JsonConvert.DeserializeObject <FacebookFeeds>(responseString); Session["FBFeed"] = feeds; foreach (FacebookFeed FBFeed in feeds.data) { String attachedImg = FBFeed.Picture; String message = FBFeed.Message; String time = FBFeed.Created_time; String link = FBFeed.Link; String linkName = FBFeed.Name; HtmlGenericControl mainDiv = new HtmlGenericControl("li"); HtmlGenericControl postUserImg = new HtmlGenericControl("img"); HtmlGenericControl divStatus = new HtmlGenericControl("div"); HtmlGenericControl p = new HtmlGenericControl("p"); HtmlGenericControl divLink = new HtmlGenericControl("div"); HtmlGenericControl attachImg = new HtmlGenericControl("img"); HtmlGenericControl commentsP = new HtmlGenericControl("p"); HtmlGenericControl divAttach = new HtmlGenericControl("div"); HtmlGenericControl attachPname = new HtmlGenericControl("p"); HtmlGenericControl attachPdesc = new HtmlGenericControl("p"); HtmlAnchor attachAHREF = new HtmlAnchor(); HtmlAnchor imgAHREF = new HtmlAnchor(); divStatus.Attributes.Add("class", "status"); p.Attributes.Add("class", "message"); p.InnerHtml = message; divStatus.Controls.Add(p); if ((link != null) && (link != String.Empty)) { divLink.Attributes.Add("class", "attachment"); if (attachedImg != "") { attachImg.Attributes["src"] = attachedImg; attachImg.Attributes.Add("class", "picture"); imgAHREF.Controls.Add(attachImg); imgAHREF.Attributes["href"] = link; imgAHREF.Attributes["target"] = "_blank"; } divAttach.Attributes.Add("class", "attachment-data"); attachPname.Attributes.Add("class", "name"); attachPdesc.Attributes.Add("class", "description"); attachPdesc.InnerText = FBFeed.Description; attachAHREF.Attributes["href"] = link; attachAHREF.Attributes["target"] = "_blank"; attachAHREF.InnerText = linkName; divLink.Controls.Add(imgAHREF); attachPname.Controls.Add(attachAHREF); divLink.Controls.Add(attachPname); divLink.Controls.Add(attachPdesc); divLink.Controls.Add(divAttach); divStatus.Controls.Add(divLink); } commentsP.Attributes.Add("class", "meta"); DateTime dt = Convert.ToDateTime(FBFeed.Created_time); commentsP.InnerHtml += ToRelativeTimeString(dt) + " "; mainDiv.Controls.Add(divStatus); mainDiv.Controls.Add(commentsP); fbLiveFeed.Controls.Add(mainDiv); } response.Close(); }