I log my users with Facebook using Passport.js and then I want to get their friends list. I use FbGraph to request Facebook graph API.
So far, so well. Facebook graph API results are paged, but I can't manage to go beyond the first page. Then responses are empty.
Here's the code:
var graph = require('fbgraph');
// accessToken is returned by Express
graph.setAccessToken(accessToken);
var getFriends = function(url) {
graph.get(url, function (err, res) {
console.log(res);
if (res.paging && res.paging.next) {
getFriends(res.paging.next);
}
});
};
getFriends('/me/friends');
And the output:
{ data:
[ { name: 'Gonzague xxx', id: 'xxx' },
{ name: 'Cyprien xxx', id: 'xxx' },
{ name: 'Chloé xxx', id: 'xxx' },
{ name: 'Elena xxx', id: 'xxx' },
{ name: 'Sari xxx', id: 'xxx' },
{ name: 'Marie xxx', id: 'xxx' } ],
paging: { next: 'https://graph.facebook.com/v2.0/xxx/friends?access_token=xxx&limit=5000&offset=5000&__after_id=enc_xxx' },
summary: { total_count: 424 } }
404
{ data: [],
paging: { previous: 'https://graph.facebook.com/v2.0/xxx/friends?access_token=xxx' },
summary: { total_count: 424 }
}