Passport.js &Facebook 图谱 API [英] Passport.js & Facebook Graph API

查看:69
本文介绍了Passport.js &Facebook 图谱 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Passport.js 和 Facebook Graph API 2.0 时遇到了一些问题.如果使用从 Passport 获得的访问令牌,我无法获得自己的朋友列表(返回空数组,但如果我请求自己的提要,则工作正常),但如果我复制从 Facebook 图中获得的访问令牌,则工作正常探索者.

I have some issue with Passport.js and Facebook Graph API 2.0. I cannot get my own friend list (returning empty array, but working fine if I requesting my own feed) if using the access token that I got from Passport but it is working fine if I copy the access token that I got from the Facebook graph explorer.

有人遇到过这个问题吗?我需要你的帮助.

Anyone have experience this issue? I need your help.

所以,这是我的一些代码:

So, here is some of my code:

路线和范围:

app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['user_friends', 'user_status', 'read_stream'] }));

对 facebook graph api 的请求(使用 Node.js 标准模块):

var fbReq = https.request({
            hostname: 'graph.facebook.com',
            method: 'GET',
            path: '/v2.0/me/friends?access_token=' + accessToken
        }, function(fbRes) {
            var output = '';
            fbRes.setEncoding('utf8');
            console.log("log the data");

            fbRes.on('data', function(chunk) {
                console.log(chunk.length);
                output += chunk;
            });

            fbRes.on('end', function() {
                return res.render('home/postLogin', { data: output });
            });

        });

        fbReq.on('error', function(err) {
            console.error(err);
        });

        fbReq.end();

提前致谢.

而且,抱歉我的英语不好.:)

And, sorry for my poor english. :)

推荐答案

刚刚阅读了 Facebook graph api v2.0 文档,所以不支持好友详细信息请求,除非任何人授予我们应用的权限.

Just read the Facebook graph api v2.0 docs, so friends details request are not supported except for anyone who have give permission to our apps.

相关文档:https://developers.facebook.com/docs/apps/upgrading

这篇关于Passport.js &Facebook 图谱 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆