Пример #1
0
        private List<Post> getTopPost(List<Counting> counting, int topNum, int start)
        {
            List<Post> topPost = new List<Post>();
            var fbClient = new Facebook.FacebookClient();
            fbClient.AccessToken = result.access_token;
            for (int i = start; i < topNum + start && i < counting.Count; i++)
            {
               // int index = counting.Count - i - 1;
                string rq = "https://graph.facebook.com/" + counting[i].id;
                var resultTmp = result.data[0];
                foreach(var e in result.data)
                {
                    if (String.Compare(e.id, counting[i].id) == 0)
                    {
                        resultTmp = e;
                        break;
                    }
                }
                //result = fbClient.Get(rq);

                //string name = result.name, link = result.link;
                //rq = counting[index].id + "?fields=picture";
                //result = fbClient.Get(rq);
                //string url = result.picture.data.url;
                User from = createUser(resultTmp.from.id, resultTmp.from.name, 0, 0, 0);
                Post tmp = new Post((string)resultTmp.id, from, (string)resultTmp.message, (string)resultTmp.picture, counting[i].comment, counting[i].liked, resultTmp.created_time);
                //tmp.Picture.Data = me.picture.data.url;
                topPost.Add(tmp);
            }
            return topPost;
        }
Пример #2
0
        public JsonResult GetComment(String postID)
        {
            if (String.Compare(accessToken, "") == 0 || postList == null)
                getData();

            List<Post> cms = new List<Post>();

            bool isContinute = true;

            for (int i = 0; i < result.data.Count && isContinute == true; i++)
            {
                if (String.Compare(result.data[i].id, postID) == 0)
                {
                    if (result.data[i].comments != null && result.data[i].comments.data.Count != 0)
                    {
                        foreach (var cm in result.data[i].comments.data)
                        {
                            User user = createUser(cm.from.id, cm.from.name, 0, 0, 0);
                            Post post = new Post(cm.id, user, cm.message, "", 0, (int)cm.like_count, cm.created_time);
                            cms.Add(post);
                        }
                        if (result.data[i].comments.data.Count == 25)
                        {
                            var fbClient = new Facebook.FacebookClient();
                            if (String.Compare(accessToken, "") == 0)
                            {
                                result = fbClient.Get("oauth/access_token", new
                                {
                                    client_id = appId,
                                    client_secret = appSecret,
                                    grant_type = "client_credentials"
                                });

                                //fbClient.AccessToken = result.access_token;
                                accessToken = result.access_token;
                            }
                            fbClient.AccessToken = accessToken;
                           // result = fbClient.Get(postID + "/comments?limit=100");//id of group
                            //need user limit and offse

                            bool isCon = true;
                            int limit = 70;
                            for (int j = 25; isCon == true; j = j + limit)
                            {
                                dynamic tmp = fbClient.Get(postID + "/comments?limit=" + limit + "&offset=" + j);

                                foreach (var cm in tmp.data)
                                {
                                    User user = createUser(cm.from.id, cm.from.name, 0, 0, 0);
                                    Post post = new Post(cm.id, user, cm.message, "", 0, (int)cm.like_count, cm.created_time);
                                    cms.Add(post);
                                }
                                if (tmp.data.Count == 0)
                                    isCon = false;
                            }

                        }
                        isContinute = false;
                    }
                }

            }
            return Json(cms, JsonRequestBehavior.AllowGet);
        }