Passport.js & Facebook Graph API

2019-07-22 18:47发布

问题:

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:

the routes and scope:

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

the request to facebook graph api (using Node.js standard module):

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();

Thannks in advance.

And, sorry for my poor english. :)

回答1:

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.

Related docs: https://developers.facebook.com/docs/apps/upgrading