11

I am trying to use Oauth2 to authenticate the google user logged in my device. I have created the client ID but I am not able to get the expected result.

Code is:

String mScope="oauth2:server:client_id:NNNNNNNNNNN.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login";

protected Void doInBackground(String... accountName) {

        Log.i("Inside on AsynTask:","I am here");
        String accName=accountName[0]; 

        try {
            token1 = GoogleAuthUtil.getToken(Web_view_demo.this,
                    accName,
                    mScope);
            Log.i("Inside on AsynTask:","I am here");
        } catch (IOException transientEx) {
            // Network or server error, try later
            Log.e("IO", transientEx.toString());
        } catch (UserRecoverableAuthException e) {
            // Recover (with e.getIntent())
            Log.e("UserRecover", e.toString());
            //Intent recover = e.getIntent();
            //startActivityForResult(recover, 1);
        } catch (GoogleAuthException authEx) {
            // The call is not ever expected to succeed
            // assuming you have already verified that 
            // Google Play services is installed.
            Log.e("GoogleAuth", authEx.toString());
        }

        Log.i("Token:",token1);
        return null;
    }

Error is:

com.google.android.gms.auth.GoogleAuthException: Unknown

Help much appreciated.

Thank you.

PramodK
  • 171
  • 1
  • 13

2 Answers2

2

For me the below format of scope worked:

String mScope="oauth2:server:client_id:123456789-dgrgfdgfdgfdgngemhmtfko16f5tnobqphb6v.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login"

Along with this if you are missing the Consent Screen set up in the Developers console for your app you might end up with this GoogleAuthException: Unknown.

PramodK
  • 171
  • 1
  • 13
  • I tried this, but in my case it did not work with client id. What did finally work is "oauth2:https://www.googleapis.com/auth/userinfo.profile", as is listed here https://developer.android.com/google/auth/http-auth.html . I'm not clear on when client id should be used or not in the scope string .. ? – Gene Bo Apr 22 '15 at 18:16
0

Also, make sure that your app ID is enabled in the Google Developer console: https://console.developers.google.com/ in APIs & Auth, Credentials, OAuth 2.0 Client IDs, Client for Android.

Martin Vysny
  • 3,088
  • 28
  • 39