【发布时间】:2016-02-05 20:04:04
【问题描述】:
我正在尝试在 Android 上获取 Auth Token,它可以在我的网络服务器上交换 accessToken 和 RefreshToken。
我正在关注this documentation。
特别是部分 - Android 应用获取 Web 后端的离线访问
我的代码:
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
事实上,我在我的 JAVA 应用程序之外使用相同的 Web 客户端 ID 使用了 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 - 我已将我的凭据仪表板图像添加为问题的一部分。
标签: java android google-oauth google-oauth-java-client