GoogleAuth访问令牌缺少userinfo.profile范围

时间:2013-09-24 11:50:09

标签: android oauth-2.0 google-plus

我有一个使用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 范围突然丢失。有关为什么会偶尔发生这种情况的任何想法?

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题