[英]Iterating through all of a user's feed using the Javascript SDK
我正在使用以下代碼遍歷用戶對其提要進行的所有發布:
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年之前都有很多狀態更新等),他們遇到的問題是相同的...
您指定的網址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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.