Barles
Barles

Reputation: 200

GoogleAuthException when obtaining an access token with ClientID

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

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

Upvotes: 10

Views: 7541

Answers (5)

edipo2s
edipo2s

Reputation: 3

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

Upvotes: 0

Ashish Saini
Ashish Saini

Reputation: 2318

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

Upvotes: 3

Dalmas
Dalmas

Reputation: 26547

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.

Upvotes: 14

Eric Woodruff
Eric Woodruff

Reputation: 6410

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.

Upvotes: 2

vlatko
vlatko

Reputation: 3344

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

Upvotes: 4

Related Questions