Passport-facebook doesn't get email [duplicate]

∥☆過路亽.° 提交于 2019-11-28 09:56:24

I had the same problem. We had 10 test users, all 10 had email addresses associated with their Facebook account. But for one of the 10 testers, Facebook did not return the 'email' JSON property in the profile response. I have no idea why, since it looked identical to other Facebook profiles that worked fine.

The fix was to change this line:

passport.authenticate('facebook')

To this:

passport.authenticate('facebook', { scope: [ 'email' ] })

I still can't explain why it worked for 9/10, but not for one. Either way, it's fixed now :-)

Ajay

Try this passport.authenticate('facebook', { scope: [ 'email' ] })

Also add a new field profileFields: [ 'email' , 'name' ] in the facebookStrategy

  passport.use(new FacebookStrategy({
    clientID: config.facebook.clientID,
    clientSecret: config.facebook.clientSecret,
    callbackURL: config.facebook.callbackURL,
    passReqToCallback:true
  },
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!