我試圖在Android上獲取身份驗證令牌,該身份驗證令牌可以在我的網絡服務器上交換爲accessToken和RefreshToken。 我正在關注this documentation。
具體的部分 - Android應用程序獲得的Web後端離線訪問無法使用GoogleAuthUtil.getToken獲取身份驗證令牌
我的代碼:
String WEB_APP_CLIENT_ID = "***.apps.googleusercontent.com";
String scopes = "oauth2:server:client_id:" + WEB_APP_CLIENT_ID+":api_scope:" + Scopes.PLUS_LOGIN + " https://www.googleapis.com/auth/plus.profile.emails.read";
//String this_scope_works_but_gives_access_token = "oauth2:" + Scopes.PLUS_LOGIN + " https://www.googleapis.com/auth/plus.profile.emails.read";
try {
String authToken = GoogleAuthUtil.getToken(AttachEmailActivity.this, account,scopes);
} catch (GoogleAuthException e) {
e.printStackTrace();
}
但它總是給我以下異常:
com.google.android.gms.auth.GoogleAuthException: Unknown
com.google.android.gms.auth.GoogleAuthUtil.zza(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
app.activities.AttachEmailActivity$1.run(AttachEmailActivity.java:437)
我已閱讀並試圖幾乎所有解決類似問題的解決方案仍然失敗。我曾嘗試使用所有不同的客戶端ID - 包括Web客戶端ID,服務器應用程序ID,Android客戶端ID,其他客戶端ID
事實上,我使用相同的Web客戶端ID在我的JAVA應用程序之外使用了rest API,獲得所需的認證碼。
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id= ****。apps.googleusercontent.com & REDIRECT_URI = http://localhost&scope=https://www.googleapis.com/auth/plus.login&access_type=offline
但在Java應用程序中,我只得到 「未知」 的例外。 不能谷歌提供更多信息?什麼是未知數?有沒有辦法獲取com.google.android.gms.auth包代碼並查看拋出異常的位置?
您是否已將密鑰註冊到Google Developer API控制檯? –
Niko - 我已將我的憑證儀表板圖像添加爲問題的一部分。 –