10

For more context, this post follows this one.

To solve my previous problem, I tried to follow the solution presented here by Tim Bray: Verifying Back-End Calls from Android Apps

I declared two projects in Google APIs Console to get two Client IDs

  • The first as "Web Application" with "localhost" as hostname (does it matter?)
    • Client ID: XXXXXXXXXX.apps.googleusercontent.com
  • The second as Android app with the package name specified in AndroidManifest.xml and SHA1 fingerprint (tried with debug.keystore and [my].keystore)
    • Client ID: YYYYYYYYYY.apps.googleusercontent.com

Unfortunately I'm facing an exception in Android side:

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)

On the line:

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

What I am doing wrong?

Thanks in advance

Community
  • 1
  • 1
Barles
  • 200
  • 2
  • 8
  • 1
    So what did you actually DO to fix the error? What did you paste into the "audience:server:client_id:..." portion? I'm getting a similar error. – Michael Alan Huff Aug 15 '14 at 01:02

5 Answers5

14

After several hours, I found that in your scope string ("audience:server:client_id:...") you have to use the Client ID of the web application, not the android one.

The client ID of the android app is unused. It's here only to link the package name of your android app with your web app.

Dalmas
  • 26,409
  • 9
  • 67
  • 80
4

The two client IDs should be part of the same project.

vlatko
  • 3,234
  • 1
  • 18
  • 11
  • I'm feeling so dumb. I thought it was the Google account that tied them. Anyway, thank you ! – Barles Jan 20 '13 at 21:20
  • Hey there! I'm facing similar problems. Can you tell me what exactly did you do to solve this? – Hick Jul 28 '13 at 11:53
  • 1
    Not sure if you have same situation. I got this error because I added Client ID for SHA1 signature got from keystore for publicing on market, but when you debugging your app from eclipse it sign it with _DEBUB KEYSTORE_ so your app will has different signature. So you need to add another Client ID with SHA fingerprint from debug.keystore See this aswer for details: http://stackoverflow.com/questions/15263228/cloud-endpoints-authentication-failure-in-android-app – Dimanoid Sep 14 '13 at 15:22
  • Since when did the GoogleAuthUtil.getToken() method start throwing a GoogleAuthException with message "BadUsername" for an email that is not registered on a device, instead of the previous exception IllegalArgumentException with message "Non existing account 'email_address'" ? http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context , java.lang.String, java.lang.String) – Etienne Lawlor Nov 06 '13 at 02:28
3

There are no need to do more. Please recreate your client id on Google console and write this line in your code as scope string .

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

https://github.com/AshishPsaini/GoogleAuth

Ashish Saini
  • 2,328
  • 25
  • 21
2

I got this error when I had changed my package name and forgot to generate a new client ID with the debug SHA1 in the Google APIs console.

Eric Woodruff
  • 6,380
  • 3
  • 36
  • 33
0

Change the scope added in GoogleApiCliente to Plus.SCOPE_PLUS_LOGIN. This work for me.

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