Search code examples
javaandroidgoogle-plusgoogle-oauth

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 ?


Solution

  • 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 ?