Google用户信息仅提供来自Android google plus的访问令牌的ID

时间:2014-01-22 12:42:46

标签: android oauth-2.0 google-plus access-token

我使用Google Plus sdk登录。如果是succces,我请求用户的访问令牌

String scope = "oauth2:" + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE;
String token = GoogleAuthUtil.getToken(context, mPlusClient.getAccountName(), scope);

它可以工作,我得到令牌,但是当我尝试它时(我会将令牌发送到服务器)我得到了这个:

https://www.googleapis.com/oauth2/v1/userinfo?access_token=ya29.xxx ...

{ id: "1060xxxxxxxxxxxxxx" }

其他数据在哪里,例如电子邮件,名称等???

我尝试了另一种方法,并将服务器部分添加到范围:

String CLIENT_ID = "abc123.apps.googleusercontent.com";
List<String> SCOPES = Arrays.asList(new String[]{
    "https://www.googleapis.com/auth/plus.login",
    "https://www.googleapis.com/auth/plus.me"
});

String scope = String.format("oauth2:server:client_id:%s:api_scope:%s", CLIENT_ID, TextUtils.join(" ", SCOPES));

但在这种情况下我总是会收到错误:

com.google.android.gms.auth.GoogleAuthException: Unknown
    at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

2 个答案:

答案 0 :(得分:1)

此处记录了完整的Google+范围:https://developers.google.com/+/api/oauth#scopes

您还可以使用OAuth Playground:https://developers.google.com/oauthplayground/来探索其他Google服务使用的范围

答案 1 :(得分:0)

我发现了问题,问题是范围。 adnroid文档仅定义了5个范围: http://developer.android.com/reference/com/google/android/gms/common/Scopes.html

String  APP_STATE   Scope for using the App State service.
String  DRIVE_FILE  Scopes for access user-authorized files from Google Drive.
String  GAMES   Scope for accessing data from Google Play Games.
String  PLUS_LOGIN  OAuth 2.0 scope for accessing the user's name, basic profile info, list of people in the user's circles, and writing app activities to Google.
String  PLUS_PROFILE    OAuth 2.0 scope for accessing the user's Google+ profile data.

但是还有其他一些例子:

"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/plus.profile.emails.read",

当我添加它们时,用户信息请求也提供了其他数据。