passport-facebook-token icon indicating copy to clipboard operation
passport-facebook-token copied to clipboard

facebook gender is empty for Sails framework?

Open ghost opened this issue 8 years ago • 7 comments
trafficstars

console.log of profile gives :

     id: '336360503408940',
  displayName: 'Ray Slim',
 name: { familyName: 'Slim', givenName: 'Ray', middleName: '' },
 gender: '',
  emails: [ { value: '' } ],
 photos: [ { value: 'https://graph.facebook.com/v2.6/336360503408940/picture?type=large' } ],
 _raw: '{"id":"336360503408940","name":"Ray Slim","last_name":"Slim","first_name":"Ray"}',
 _json: 
  { id: '336360503408940',
   name: 'Ray ',
     last_name: 'Ray Slim',

As you can see, gender has no value. Why is that? Below is my token strategy, similar to a lot of them

var facebookLoginStrategy = new FacebookTokenStrategy({ clientID: '1512072982155691', clientSecret: '7b89b4bdfba3408b68efe9fd1c3a8164' }, function(accessToken, refreshToken, profile, done) {

User.findOrCreate({ id: profile.id}, function (err, user) {

console.log(profile)

return done(err, user);

});

});

ghost avatar Dec 15 '16 06:12 ghost

It seems to be showing on everyone else's.. is it just a sails thing?

ghost avatar Dec 15 '16 06:12 ghost

@rslim087g could be that profile you got just doesn't have gender property.

ghaiklor avatar Dec 15 '16 10:12 ghaiklor

I tried three profiles. If I do a facebook graph request on the client side it gives me gender for all of them.

ghost avatar Dec 15 '16 15:12 ghost

Could it be a framework or library that I'm not using ?

ghost avatar Dec 15 '16 15:12 ghost

only frameworks I'm using are app.use(bodyParser.json()); , and passport.use(facebookLoginStrategy) , do I need some other parser for things like gender??

ghost avatar Dec 15 '16 15:12 ghost

figured it out, had to add this

clientID: '1512072982155691',
clientSecret: '7b89b4bdfba3408b68efe9fd1c3a8164',

------> profileFields: ['id', 'displayName', 'gender']

ghost avatar Dec 15 '16 16:12 ghost

relates to #68 @ghaiklor seems to be an outdated doc issue

agalazis avatar Jul 22 '17 15:07 agalazis