2014-01-22 46 views
1

我使用Google Plus SDK登錄。如果是succces,我請求用戶的訪問令牌谷歌用戶信息只給出從Android谷歌訪問令牌的ID加

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" } 

其他數據,例如電子郵件,姓名等?

我嘗試另一個soution和我添加的服務器部分,範圍:

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) 

回答

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", 

,當我加入他們的用戶信息請求gaved其他數據了。

相關問題