简体   繁体   English

护照facebook身份验证不提供电子邮件地址

[英]passport facebook authentication is not providing email address

i did all ways that are explained in Stackoverflow but it didn't work 我做了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);
  }
));

and

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

but in my console 但在我的控制台

 _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' } }

there are no email fields what is problem? 没有电子邮件字段有什么问题? or is there any problem in my facebook account authorization? 或者我的Facebook帐户授权有问题吗?

in the profileFields object, use 'email' instead of 'emails. 在profileFields对象中,使用“email”而不是“email”。

profileFields:['id', 'emails', 'link', 'locale', 'name',
  'timezone', 'updated_time', 'verified', 'displayName']

replace with 用。。。来代替

profileFields:['id', 'email', 'link', 'locale', 'name',
  'timezone', 'updated_time', 'verified', 'displayName']

Try this: 尝试这个:

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

and

app.get(
  '/auth/facebook',
   passport.authenticate(
     'facebook',
     {scope:['public_profile', 'email']}
   )
 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM