我做了Stackoverflow中解释的所有方法,但它没有工作
passport.use(new FacebookStrategy({
clientID: 'CLIENT ID',
clientSecret: 'CLIENT SECRET',
callbackURL: "/auth/facebook/callback",
profileFields:['id', 'emails', 'link', 'locale', 'name',
'timezone', 'updated_time', 'verified', 'displayName']
},
function(accessToken, refreshToken, profile, done) {
console.log(profile);
var authId = 'facebook:' + profile.id;
for(var i = 0; i < users.length; i++){
var user = users[i];
if(user.authId === authId){
return done(null, user);
}
}
var new_user = {
'authId':authId,
'displayName':profile.displayName
};
users.push(new_user);
done(null, new_user);
}
));
和
app.get(
'/auth/facebook',
passport.authenticate(
'facebook',
{scope:['email']}
)
);
但在我的控制台
_json:
{ id: 'MY ID',
link: 'https://www.facebook.com/app_scoped_user_id/MY_ID/',
locale: 'ko_KR',
last_name: 'LAST_NAME',
first_name: 'FIRST_NAME',
timezone: 9,
updated_time: '2016-06-26T06:25:28+0000',
verified: true,
name: 'MY NAME' } }
没有电子邮件字段有什么问题? 或者我的Facebook帐户授权有问题吗?
答案 0 :(得分:0)
在profileFields对象中,使用&#39; email&#39;而不是电子邮件。
200-00-0000
替换为
profileFields:['id', 'emails', 'link', 'locale', 'name',
'timezone', 'updated_time', 'verified', 'displayName']
答案 1 :(得分:0)
试试这个:
passport.use(new FacebookStrategy({
clientID: 'CLIENT ID',
clientSecret: 'CLIENT SECRET',
callbackURL: "/auth/facebook/callback",
profileFields:['id', 'emails', 'link', 'locale', 'name',
'timezone', 'updated_time', 'verified', 'displayName']
},
function(accessToken, refreshToken, profile, done) {
console.log(profile.emails[0].value);
var authId = 'facebook:' + profile.id;
for(var i = 0; i < users.length; i++){
var user = users[i];
if(user.authId === authId){
return done(null, user);
}
}
var new_user = {
'authId':authId,
'displayName':profile.displayName
};
users.push(new_user);
done(null, new_user);
}
));
和
app.get(
'/auth/facebook',
passport.authenticate(
'facebook',
{scope:['public_profile', 'email']}
)
);