0

我正在使用以下代码来遍历用户曾经对其提要发布的所有帖子:

        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                // the user is logged in and has authenticated your
                // app, and response.authResponse supplies
                // the user's ID, a valid access token, a signed
                // request, and the time the access token 
                // and signed request each expire

                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;

                var fbid = response.authResponse.userID;

                console.time('all posts');

                var url = '/me/feed?limit=100';
                var finished = false;
                var c = 0, totalLikes = 0;
                var timer = setInterval(function () {

                    if(url != '') {
                        console.log("Checking: " + url);
                        FB.api(url, function(response) {

                            //console.log("Got " + response.data.length + " items");

                            //c += response.data.length;

                            // calculate total likes
                            for(var k in response.data) {
                                c++;
                                if(response.data[k].from.id == fbid) {
                                    console.log(response.data[k]);

                                }

                            }

                            if(response.paging) {
                                var bits = response.paging.next.split('facebook.com');
                                url = bits[1];
                            } else { 
                                clearInterval(timer); 
                                console.log("Found a total of " + c + " items");
                                console.timeEnd('all posts')
                            }
                        });
                        url = '';
                    } else {
                         //console.log("Skipped iteration");
                    }
                }, 1000);

            } else if (response.status === 'not_authorized') {
                // the user is logged in to Facebook, 
                // but has not authenticated your app

                FB.login(function(response) {
                    if (response.authResponse) {
                        console.log('Welcome!  Fetching your information.... ');
                        FB.api('/me', function(response) {
                            console.log('Good to see you, ' + response.name + '.');
                        });
                    } else {
                        console.log('User cancelled login or did not fully authorize.');
                    }
                }, { scope: 'user_about_me,read_stream,user_status,user_photos,friends_about_me,user_checkins,friends_likes,user_actions.music' });

            } else {
                // the user isn't logged in to Facebook.
                console.log("not logged in");
            }   
        });

不幸的是,它似乎在遍历页面时,没有找到粘贴 2011 的更新,然后在最后一页上找到了我在 2007 年对另一个用户的状态发表的两条评论。它实际上缺少我所做的 100 条状态更新。

我花了最后三个小时研究这个,但无济于事。我尝试了 3 个不同的人的帐户(在 2011 年之前,他们都有很多状态更新等)并且他们有同样的问题......

4

1 回答 1

0

您指定的 URL, var url = '/me/feed?limit=100';因此它只返回前 100 个。您可以尝试增加限制,也可以像这样使用偏移量:

var url = '/me/feed?limit=100&offset=101

相关的api文档:https ://developers.facebook.com/docs/reference/api/

经过进一步搜索,似乎有一些关于历史记录的错误。

https://developers.facebook.com/bugs/178108638946497?browse=search_4fabbf595050e1514377846

于 2012-05-09T12:49:43.153 回答