即使在范围内,Passport-Facebook也不提供电子邮件

在我的应用程序中,我注册了facebook-strategie如下:但是返回的configuration文件不包含电子邮件字段….

passport.use(new FacebookStrategy({ clientID: config.facebook.clientID, clientSecret: config.facebook.clientSecret, callbackURL: config.facebook.callbackURL, passReqToCallback: true }, function(req, accessToken, refreshToken, profile, done) { // No email in the following colsole.log console.log(JSON.stringify(profile)); })); 

得到如下:

 app.get('/oauth/facebook', passport.authenticate('facebook', { failureRedirect: '/login', scope:['email'] })); 

(所以我使用范围如这里所说: Passport-Facebook不会收到电子邮件 )

在FBlogin页面我甚至要求电子邮件,我确实提供: 在这里输入图像描述

任何帮助非常appriciated!

从Facebook图APIv2.4中,我们需要明确指定要获取的字段。

介绍Graph API v2.4

所以,我们可以这样写:

  passport.use(new FacebookStrategy({ clientID: config.facebook.clientID, clientSecret: config.facebook.clientSecret, callbackURL: config.facebook.callbackURL, profileFields: ['id', 'email', 'gender', 'link', 'locale', 'name', 'timezone', 'updated_time', 'verified'], }, 

你有代码的callback部分,对吧?

 app.get('/oauth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login', successRedirect: '/', scope:['email'] })); 

而且,的确,这应该在scope:['email']完成scope:['email'] ,根据您的链接和这里的说明 。