我使用下面的代碼通過一個用戶曾經到他們的原料製成的所有帖子迭代用戶的飼料:迭代通過所有使用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年之前都有很多狀態更新等),並且他們有相同的問題...
該文檔指出,限制僅限制每頁上的結果數量。我的理解是,JSON對象中的paging.next屬性將正確帶我到下一個URL。 我找不到任何引用,它使用你描述的語法(它只是建議他們作爲參數) 我嘗試使用圖形API瀏覽器:/ me/feed?limit = 2&offset = 10'和'/me/feed?limit = 2&offset = 10',但它停止返回偏移10附近的數據。我不確定這是否是正確的解決方案... – Dean
讓我編輯我的最新評論。從limit = 100開始,下一頁應該是「limit = 100&offset = 101'和」limit = 100&offset = 202「等。在他們的api頁面上,手動測試這種情況,你應該能夠成功地瀏覽頁面。下一頁確實會返回這些行,但您也可以手動測試它們。 '{ previous:「https://graph.facebook.com/me/feed?limit=5&access_token=mytoken&since=1336449559&__previous=1」, next:「https://graph.facebook.com/me/feed?limit = 5&access_token = mytoken&until = 1336053590「 }' – lucuma