【问题标题】:GoogleAuth access token is missing the userinfo.profile scopeGoogleAuth 访问令牌缺少 userinfo.profile 范围
【发布时间】:2023-03-15 18:03:01
【问题描述】:

我有一个使用 Google Plus API 的 android 应用程序,我还要求提供一个访问令牌,我将其传递给我的服务器,以便我可以调用 oauth 2.0 API 来获取用户详细信息。 我要求使用GoogleAuthUtil.getToken 的访问令牌,其范围如下:

String scopes = "oauth2: https://www.googleapis.com/auth/userinfo.profile 
                         https://www.googleapis.com/auth/userinfo.email 
                         https://www.googleapis.com/auth/plus.login" ;

然后,我将获得的访问令牌传递给我的服务器,并进行 api 调用:https://www.googleapis.com/oauth2/v2/userinfo 它返回以下用户详细信息:[id, email, verified, name, given_name, family_name, link, picture, gender, locale]

到目前为止一切顺利。 这在 90% 的时间里都有效。最近我得到的用户没有大部分细节。当我检查他们的访问令牌时,我看到以下内容:

{
"issued_to": "534771845378-a8epgha85s5hkr3bqnsj8ihjvpl8pms.apps.googleusercontent.com",
"audience": "534771845378-ha8epgha85s5hkr3bqnsj8ihjvpl8pms.apps.googleusercontent.com",
"user_id": "103098746579631883577",
"scope": "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email",
"expires_in": 3382,
"email": "***@***.com",
"verified_email": true,
"access_type": "offline"
} 

请注意,userinfo.profile 范围突然丢失。有没有想过为什么有时会发生这种情况?

【问题讨论】:

    标签: android oauth-2.0 google-plus


    【解决方案1】:

    这可能是因为越来越多的信息存储在具有不同访问控制的 Google+ 个人资料中,而不是旧的用户个人资料中。

    您可以使用https://www.googleapis.com/plus/v1/people/me 端点在 plus.login 范围内获取他们的 public 个人资料信息,但这只有在他们公开他们的信息的情况下才会这样做。您也将无法使用此端点获取他们的电子邮件 - 您仍然需要使用 oauth userinfo 端点。

    有关更多详细信息和其他可用端点,请参阅https://developers.google.com/+/api/latest/

    【讨论】:

      猜你喜欢
      • 2020-02-10
      • 2015-05-16
      • 2017-05-13
      • 1970-01-01
      • 2019-09-22
      • 1970-01-01
      • 2020-10-05
      • 2016-09-18
      • 2020-11-05
      相关资源
      最近更新 更多