jaredhanson / passport-facebook

Facebook authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-facebook/?utm_source=github&utm_medium=referral&utm_campaign=passport-facebook&utm_content=about
MIT License
1.3k stars 446 forks source link

Friends not appearing on profile object even though included in _json #170

Open dawningfuture opened 8 years ago

dawningfuture commented 8 years ago

I am trying to get the friend list for users that use my app. Here's my route:

app.get('/login/facebook', passport.authenticate('facebook-login', { 'scope': ['email', 'public_profile', 'user_friends'] }))

and my passport-facebook config object:

var facebookLoginStrategy = new FacebookStrategy({ clientID: process.env.FACEBOOK_APP_ID, clientSecret: process.env.FACEBOOK_APP_SECRET, callbackURL: process.env.API_URL + "/login/facebook-callback", passReqToCallback: true, profileFields: ['email', 'friends', 'displayName', 'picture.type(large)'] }, function(req, accessToken, refreshToken, profile, done) { console.log(profile) ... })

Here's what's logged:

{ id: 'xxx', username: undefined, displayName: 'xxx', name: { familyName: undefined, givenName: undefined, middleName: undefined }, gender: undefined, profileUrl: undefined, emails: [ { value: 'xxx' } ], photos: [ { value: 'xxx' } ], provider: 'facebook', _raw: '...', _json: { email: '...', friends: { data: [Object], paging: [Object], summary: [Object] }, name: '...', picture: { data: [Object] }, id: 'xxx' } }

As you can see, the friends object is returned in the _json object, but not in the profile object itself. Is this a bug with passport-facebook, or with the Facebook API itself? Thanks in advance for any help.

rafipiccolo commented 8 years ago

fcebook is shit. maybe this time the lib is shit, but as displayed, this should work, noob :) console.log(profile._json.friends);

dawningfuture commented 8 years ago

For sure I resorted to that, just figured I could improve the lib with a PR (in progress)

kanodianeha commented 7 years ago

I face a similar issue, but not with "friends" with "work" and "education" fields. They are present in raw and _json, but not part of profile object itself.