コード例 #1
0
        /// <summary>
        /// Gets the News Feeds of the Facebook Page
        /// </summary>
        /// <returns>Returns list of Feeds of type "Picture" from MQ163 page</returns>
        public IEnumerable<IFacebookPost> GetAllNewsFeed()
        {
            #region Initialize objects and URL
                var json = new JavaScriptSerializer();
                List<IFacebookPost> postsList = new List<IFacebookPost>();

                string Url = string.Format("{0}/MQ163/posts?method=GET&format=json&access_token={1}", _baseUrl, AccessToken);
            #endregion

            using (var webClient = new WebClient())
            {
                string data = webClient.DownloadString(Url);

                #region parse Facebook feed data
                    var feeds = (Dictionary<string, object>)json.DeserializeObject(data);
                    object[] feedsArray = (object[])feeds.FirstOrDefault(p => p.Key == "data").Value;
                    foreach (object feed in feedsArray)
                    {
                        IFacebookPost post = new FacebookPost();
                        Dictionary<string, object> feed2 = (Dictionary<string, object>)feed;

                        post.Id = feed2["id"].ToString();

                        if (feed2.Keys.Contains("message"))
                        {
                            post.PostText = feed2["message"].ToString();
                        }
                        else
                        {
                            post.PostText = "No message title.";
                        }

                        if (feed2.Keys.Contains("comments"))
                        {
                            int value = 0;
                            Int32.TryParse((feed2["comments"] as Dictionary<string, object>)["count"].ToString(), out value);
                            post.CommentCount = value;
                        }
                        else
                        {
                            post.CommentCount = 0;
                        }

                        if (feed2.Keys.Contains("likes"))
                        {
                            int value = 0;
                            Int32.TryParse((feed2["likes"] as Dictionary<string, object>)["count"].ToString(), out value);
                            post.LikeCount = value;
                        }
                        else
                        {
                            post.LikeCount = 0;
                        }

                        postsList.Add(post);

                    }
                #endregion
            }
            return postsList;
        }
コード例 #2
0
ファイル: FacebookAgent.cs プロジェクト: SeshuMiriyala/MQ163
        /// <summary>
        /// Gets the News Feeds of the Facebook Page
        /// </summary>
        /// <returns>Returns list of Feeds of type "Picture" from MQ163 page</returns>
        internal IEnumerable<IFacebookPost> GetAllFeeds()
        {
            var json = new JavaScriptSerializer();
            List<IFacebookPost> postsList = new List<IFacebookPost>();
            string Url = string.Format("{0}/MQ163/feed?filter={2}&access_token={1}", baseUrl, AccessToken, "app_2305272732");

            try
            {
                using (var webClient = new WebClient())
                {
                    string data = webClient.DownloadString(Url);
                    var feeds = (Dictionary<string, object>)json.DeserializeObject(data);
                    object[] feedsArray = (object[])feeds.FirstOrDefault(p => p.Key == "data").Value;
                    foreach (object feed in feedsArray)
                    {
                        IFacebookPost post = null;
                        Dictionary<string, object> feed2 = (Dictionary<string, object>)feed;
                        if (feed2.Keys.Contains("message") && null != feed2["message"] && "photo" == feed2["type"].ToString())
                        {
                            post = new FacebookPost();
                            post.PostText = feed2["message"].ToString();
                            post.Id = feed2["id"].ToString();
                            post.PostPicture = feed2["picture"].ToString();
                            post.Likes = GetAllLikesForPost(feed2["id"].ToString());
                            post.Comments = GetAllCommentsForPost(feed2["id"].ToString());
                            postsList.Add(post);
                        }
                    }
                }
                return postsList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the News Feeds of the Facebook Page
        /// </summary>
        /// <returns>Returns list of Feeds of type "Picture" from MQ163 page</returns>
        public IEnumerable <IFacebookPost> GetAllNewsFeed()
        {
            #region Initialize objects and URL
            var json = new JavaScriptSerializer();
            List <IFacebookPost> postsList = new List <IFacebookPost>();

            string Url = string.Format("{0}/MQ163/posts?method=GET&format=json&access_token={1}", _baseUrl, AccessToken);
            #endregion

            using (var webClient = new WebClient())
            {
                string data = webClient.DownloadString(Url);

                #region parse Facebook feed data
                var      feeds      = (Dictionary <string, object>)json.DeserializeObject(data);
                object[] feedsArray = (object[])feeds.FirstOrDefault(p => p.Key == "data").Value;
                foreach (object feed in feedsArray)
                {
                    IFacebookPost post = new FacebookPost();
                    Dictionary <string, object> feed2 = (Dictionary <string, object>)feed;

                    post.Id = feed2["id"].ToString();

                    if (feed2.Keys.Contains("message"))
                    {
                        post.PostText = feed2["message"].ToString();
                    }
                    else
                    {
                        post.PostText = "No message title.";
                    }

                    if (feed2.Keys.Contains("comments"))
                    {
                        int value = 0;
                        Int32.TryParse((feed2["comments"] as Dictionary <string, object>)["count"].ToString(), out value);
                        post.CommentCount = value;
                    }
                    else
                    {
                        post.CommentCount = 0;
                    }

                    if (feed2.Keys.Contains("likes"))
                    {
                        int value = 0;
                        Int32.TryParse((feed2["likes"] as Dictionary <string, object>)["count"].ToString(), out value);
                        post.LikeCount = value;
                    }
                    else
                    {
                        post.LikeCount = 0;
                    }


                    postsList.Add(post);
                }
                #endregion
            }
            return(postsList);
        }