Passport-facebook没有收到电子邮件

jca*_*llo 13 node.js facebook-graph-api express passport-facebook

我已经使用快递js和passport-Facebook在我的网站上实现了Facebook-LogIn.它运作良好(我获得现场简介),但问题是我没有收到电子邮件.我收到一个错误:

email   : profile.emails[0].value,
Run Code Online (Sandbox Code Playgroud)

TypeError:无法读取未定义的属性"0"

我的代码:

passport.use('facebook',new FacebookStrategy({
        clientID            : config.facebook.id,
        clientSecret    : config.facebook.secret,
        callbackURL  : '/auth/facebook/callback',
        profileFields : ['id', 'displayName', 'emails','photos']
    }, function(accessToken, refreshToken, profile, done) {

        User.findOne({provider_id: profile.id}, function(err, user) {
            if(err) throw(err);
            if(!err && user!= null) return done(null, user);

            var user = new User({
                provider_id : profile.id,
                name                 : profile.displayName,
                email               : profile.emails[0].value,
                photo               : profile.photos[0].value,
            });
            user.save(function(err) {
                if(err) throw err;
                return done(null, user);
            });
        });
    }));
Run Code Online (Sandbox Code Playgroud)

如果有人可以帮我解决我的问题,那将会很棒:)

Ale*_*ork 12

我有同样的问题.我们有10个测试用户,所有10个用户的Facebook帐户都有电子邮件地址.但对于10位测试者中的一位,Facebook没有在个人资料回复中返回"email"JSON属性.我不知道为什么,因为它看起来与其他Facebook配置文件完全相同.

解决方法是更改​​此行:

passport.authenticate('facebook')
Run Code Online (Sandbox Code Playgroud)

对此:

passport.authenticate('facebook', { scope: [ 'email' ] })
Run Code Online (Sandbox Code Playgroud)

我仍然无法解释为什么它适用于9/10,但不适用于一个.无论哪种方式,它现在已经修好:-)