【问题标题】:How to get user address and phone number from google auth如何从 google auth 获取用户地址和电话号码
【发布时间】:2019-09-03 19:52:43
【问题描述】:

我正在使用passport.js 使用passport-google-oauth20 进行身份验证,

我想知道如何获取地址、电话号码等用户信息?到目前为止,我只能获取电子邮件、姓名、个人资料等信息,但不能获取地址和电话号码。用谷歌登录后如何访问用户数据地址?

是否有任何 API 可以访问此用户地址和电话号码?我该怎么办?

这是我的代码:

护照设置

passport.use(
    new GoogleStrategy({
        //options for the google strategy
        callbackURL: keys.origin.url + '/api/auth/google/redirect',
        clientID: keys.google.clientID,
        clientSecret: keys.google.clientSecret,
        userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
    }, (accessToken, refreshToken, profile, done) => {
          console.log(profile);
    })

);

路线

routes.get('/auth/google',passport.authenticate("google",{
    scope: ["profile", "email"]
}));

【问题讨论】:

    标签: node.js google-api passport.js


    【解决方案1】:
        routes.get('/auth/google',passport.authenticate("google",{
        scope: [
            'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email',
            'https://www.googleapis.com/auth/user.phonenumbers.read',
            'https://www.googleapis.com/auth/user.addresses.read',
            'https://www.googleapis.com/auth/profile.agerange.read'
      ]
    }));
    

    这会返回用户数据

    【讨论】:

      猜你喜欢
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2020-09-23
      • 1970-01-01
      相关资源
      最近更新 更多