Javascript 使用Facebook graph API在Node.js中检索整个好友列表

Javascript 使用Facebook graph API在Node.js中检索整个好友列表,javascript,node.js,facebook,facebook-graph-api,Javascript,Node.js,Facebook,Facebook Graph Api,我使用Passport.js将我的用户登录到Facebook,然后我想获得他们的好友列表。我使用请求Facebook图形API 到目前为止,一切顺利。Facebook graph API结果已分页,但我无法超越第一页。然后回答是空的 代码如下: var graph = require('fbgraph'); // accessToken is returned by Express graph.setAccessToken(accessToken); var getFriends = fun

我使用Passport.js将我的用户登录到Facebook,然后我想获得他们的好友列表。我使用请求Facebook图形API

到目前为止,一切顺利。Facebook graph API结果已分页,但我无法超越第一页。然后回答是空的

代码如下:

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');
以及输出:

{ 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 } 
}

不幸的是,你无法在Graph API 2.0+上获取完整的好友列表,你只能获取正在使用你的应用程序的好友(使用means,已在Facebook上授予该应用程序的权限)。
total_count
键表示用户有424个朋友,但并不意味着你可以从应用程序中获得所有424个朋友


您看到的列表只是授权您的应用程序的人,由于只有少数人,分页会产生一个空结果,因为您看到的就是您的全部。

真的吗?我在PHP中使用了相同的实现,它返回了整个friendList。在JS中有这样做的方法吗(可能通过使用以前版本的API…)@user1717735什么时候?如果是在强制Graph API 2.0迁移(2015年4月30日)之前,那么这是可能的,不幸的是,现在不是。您可以尝试查看Graph API 2.3中引入的“all_mutual_friends”边缘,如果两个应用程序用户之间的好友信息足够的话,它可能会提供您正在寻找的内容。请参见Graph API 2.3的新特性:是的,我上次尝试PHP实现是在4月份之前。然后,对于一个测试应用程序,如果你没有任何朋友使用该应用程序,你如何测试(不要对我的朋友说“嘿,登录这个,这样我就可以进行测试了!”)?另一个在matter@user1717735您可以在应用程序的开发人员控制台上创建测试用户。