Passport-facebook没有收到邮件 [英] Passport-facebook doesn't get email

查看:233
本文介绍了Passport-facebook没有收到邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的网站上使用快速js和护照 - Facebook实现了Facebook-LogIn。它工作得很好(我得到现场简介),但问题是我没有收到电子邮件。我收到一个错误:

I have already implemented the Facebook-LogIn in my website with express js and passport-Facebook. It works well (I get field profile), but the problem is that I don't get the Email. I get an error:

email   : profile.emails[0].value,

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

TypeError: Cannot read property '0' of undefined

我的代码:

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);
            });
        });
    }));

如果有人可以帮助我解决问题,这将是很棒的:)

It would be great if someone could help me with the solution to my problem :)

推荐答案

我也有同样的问题。我们有10个测试用户,所有10个都有与他们的Facebook帐户相关联的电子邮件地址。但是,对于10个测试人员中的一个,Facebook在配置文件回复中没有返回电子邮件JSON属性。我不知道为什么,因为它看起来与其他Facebook档案工作正常相同。

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.

修复是改变这一行:

passport.authenticate('facebook')

to this:

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

我仍然无法解释为什么它工作在9/10,但不是一个。无论哪种方式,现在都是固定的: - )

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

这篇关于Passport-facebook没有收到邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆