22

I have android, google authorization issue (similar to .GoogleAuthException: Unknown while doing Google SSO. - no answers):

09-29 00:04:38.328: W/System.err(15623): com.google.android.gms.auth.GoogleAuthException: Unknown
09-29 00:04:38.328: W/System.err(15623):    at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

It is reproducable when i execute the following code:

String scopesString = Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE;
String scopes = "oauth2:server:client_id:" + Consts.GOOGLE_PLUS_SERVER_CLIENT_ID + ":api_scope:" + scopesString;
OR
String scopes = "audience:server:client_id:" + Consts.GOOGLE_PLUS_SERVER_CLIENT_ID;
Bundle appActivities = new Bundle();
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "http://schemas.google.com/AddActivity http://schemas.google.com/BuyActivity");
GoogleAuthUtil.getToken(activity,  accountName, scopes, appActivities);

Here are some notes:

  1. I can get access token with GoogleAuthUtil.getToken(activity, accountName, "oauth2:" + scopesString)
  2. activity != null, client_id = 123456789.apps.googleusercontent.com, accountName is valid email (selected with account picker)
  3. accountName in http://plus.google.com/u/0/apps has a record about my project: <Project Name> ------- app and purchase activity--------Your circles
  4. I have android.permission.GET_ACCOUNTS
  5. The same exception with appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "")
  6. The same exception with GoogleAuthUtil.getToken(activity, accountName, scopes)

SOLVED

  1. You should have 2 Client Ids: Installed App (Android) and Service one. You should use Service one here.
  2. Then you will get UserRecoverableAuthException: NeedPermission. You should handle exception

i.e. like this:

} catch (UserRecoverableAuthException e) {
activity.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}
Community
  • 1
  • 1
Carl Haroldson
  • 221
  • 3
  • 4
  • Hm, I'm pretty sure the version that begins with "oauth2:" is right. Can you get a message out of the exception, or by having a look in logcat? – Tim Bray Sep 28 '13 at 21:08
  • 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:38
  • What do you mean by "Service one"? Can I get it from the Developers Console? – CheatEx Sep 08 '14 at 13:03

4 Answers4

7

In the Google Developer Console, in the APIs & Auth section click Credentials.

You probably already have a "Client ID for Android application" and are using that Client ID. What you have to do is create a new Client ID and select "Service Account" for your backend.

You must use this Client ID, and not the Android one.

zundi
  • 2,361
  • 1
  • 28
  • 45
0

I was getting the Unknown error because I registered my SHA1 hash using my release keystore. Registering a new app using a debug keystore fixed my issue.

eliasbagley
  • 1,237
  • 9
  • 17
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
0

For me it happened when I changed the "applicationId" in the gradle file. Make sure you have the same applicationId or packagename in the developer console when you enabled the API.

S.Javed
  • 383
  • 3
  • 8