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();