Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown GoogleAuthException while trying to get an authorization token

I'm trying to get an authorization token from Google+ using their sdk on Android, but it always raises an 'GoogleAuthException Unknown'

Here is the code I use :

private static final String LOGIN_SCOPES =
        "https://www.googleapis.com/auth/plus.login " +
        "https://www.googleapis.com/auth/userinfo.email";

protected static final String SCOPES = 
        "oauth2:server:client_id:" + 
        BuildConfig.GOOGLE_SERVER_CLIENT_ID + 
        ":api_scope:" + 
        LOGIN_SCOPES;

String token = GoogleAuthUtil.getToken(
                        getApplicationContext(),
                        Plus.AccountApi.getAccountName(googleApiClient),
                        SCOPES);

I doubled checked the client_id I got from the google console.

What is really troubling is that this code works for my staging flavor, with a staging client_id, but for my production client_id which I just created this morning, I can't make it work.

Any idea ?

like image 883
trupin Avatar asked Oct 19 '22 14:10

trupin


2 Answers

I finally found out what was going wrong. I was using the android client id instead of the web one. It turns out that in this case, Google+ cannot give you more details about the error than "Unknown".

So if someone else faces this "Unknown" exception from Google+, you can start checking these two points :

  • are you using the web client id in your scope (and not another one) ?
  • are you 100% sure that your SHA1 certificate is good ?
like image 77
trupin Avatar answered Oct 29 '22 17:10

trupin


I had the same problem. I used sample project Auth from sdk and I made it work.

like image 45
dhun Avatar answered Oct 29 '22 17:10

dhun