对于我的应用程序(Node.js),我使用的是passport-facebook,除了我无法收到用户电子邮件之外,一切正常。我在这个问题上发现了很多问题,但由于某种原因他们没有解决我的问题。我真的很想得到一些帮助。所以我的配置:
app.js
app.get('/auth/facebook', passport.authenticate('facebook', {scope: 'email'}));
// in scope i tried a different options like ['email'] or ['emails'] and so go on
app.get('/auth/facebook/callback',
passport.authenticate('facebook', {
successRedirect: '/',
failureRedirect: '/login'
}));
passport.js:
passport.use('facebook', new FacebookStrategy({
clientID : secret.facebook.clientID,
clientSecret : secret.facebook.clientSecret,
callbackURL : secret.facebook.callback
},
function(access_token, refreshToken, profile, done) {
console.log(profile) // here i got all profile data except email
process.nextTick(function() {
User.findOne({ 'facebook.id' : profile.id }, function(err, user) {
if (err)
return done(err);
if (user) {
return done(null, user);
} else {
var newUser = new User();
console.log(profile.email) // here i got undefined
newUser.facebook.id = profile.id;
newUser.facebook.token = access_token;
newUser.facebook.firstName = profile.name.givenName;
newUser.facebook.lastName = profile.name.familyName;
newUser.facebook.email = profile.email;
newUser.save((err) => {
if (err)
throw err;
return done(null, newUser);
});
}
});
});
}));
Facebook的secret.js
module.exports = {
facebook: {
clientID: '****',
clientSecret: '********',
callback: '/auth/facebook/callback',
profileFields: ['id', 'email']
}
}
在UserSchema中:
facebook: {
id: String,
token: String,
email: String,
name: String,
}
graph - api
答案 0 :(得分:1)
在passport.js中:
tf.equal
更改为:
{{1}}
我的个人资料字段:个人资料字段:[' ID',' displayName',' email',' first_name',' middle_name& #39;,' last_name']
答案 1 :(得分:0)
尝试将url中的作用域传递为图API中使用的param(?fields = id,email ...)。