10

有关更多上下文,本文后跟this oneGoogleAuthException在获取带有ClientID的访问令牌时

为了解决我以前的问题,我试图按照由蒂姆·布雷这里提出的解决方案:Verifying Back-End Calls from Android Apps

我在谷歌API控制台申报两个项目拿到两个端ID

  • 第一为 “Web应用程序” 与 “localhost” 作为主机名(这很重要?)
    • 客户端ID:XXXXXXXXXX.apps.googleusercontent.com
  • 第二如Android应用与在AndroidManifest.xml和SHA1指纹指定的包名称(试图用debug.keystore和[我的]的.keystore)
    • 客户ID:YYYYYYYYYY.apps。 googleusercontent.com

不幸的是我现在面临Android中端异常:

com.google.android.gms.auth.GoogleAuthException: Unknown 
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 
at fr.barles.android.activity.LoginActivity$1.doInBackground(LoginActivity.java:66) 
at fr.barles.android.activity.LoginActivity$1.doInBackground(LoginActivity.java:1) 
at android.os.AsyncTask$2.call(AsyncTask.java:185) 
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 
at java.lang.Thread.run(Thread.java:1102) 

就行了:

return GoogleAuthUtil.getToken(LoginActivity.this, account[0], "audience:server:client_id:XXXXXXXXXX.apps.googleusercontent.com"); 

我做错了吗?

在此先感谢

+1

那么你究竟做了什么来解决这个错误?你把什么粘贴到“观众:服务器:client_id:...”部分?我收到类似的错误。 –

回答

4

这两个客户端ID应该是同一个项目的一部分。

+0

我感觉很愚蠢。我认为这是与他们绑定的Google帐户。 无论如何,谢谢! – Barles

+0

嘿!我面临类似的问题。你能告诉我你到底做了什么来解决这个问题吗? – Hick

+1

不确定你是否有同样的情况。 我得到了这个错误,因为我在keystore上添加了客户端ID,用于在市场上公开,但是当您从eclipse调试您的应用程序时,它使用_DEBUB KEYSTORE_对其进行签名,以便您的应用程序具有不同的签名。 因此,您需要从debug.keystore中添加另一个带SHA指纹的客户端ID 有关详细信息,请参阅此应用程序:http://stackoverflow.com/questions/15263228/cloud-endpoints-authentication-failure-in-android-app – Dimanoid

2

当我更改包名并忘记在Google API控制台中使用调试SHA1生成新的客户端ID时,出现此错误。

14

几个小时后,我发现在您的作用域字符串("audience:server:client_id:...")中,您必须使用Web应用程序的客户端ID,而不是Android。

android应用程序的客户端ID未使用。这里只是将你的android应用程序的包名与你的web应用程序链接起来。

+3

After several几小时的搜索,我找到了你的帖子! – Pongpat

3

有没有必要做更多。 请在Google控制台上重新创建您的客户端ID,并将该行作为范围字符串写入代码中。

String SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile"; 

https://github.com/AshishPsaini/GoogleAuth

0

变化GoogleApiCliente加入Plus.SCOPE_PLUS_LOGIN范围。这为我工作。

googleApiClient = new GoogleApiClient.Builder(this) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .addApi(Plus.API) 
      .addScope(Plus.SCOPE_PLUS_LOGIN) 
      .build();