6

I am using these below lines of code for G+ sign-in android integration.

In app build.gradle :

compile 'com.google.android.gms:play-services-auth:8.4.0' compile 'com.google.android.gms:play-services-plus:8.4.0'

In MainActivity :

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestIdToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com")
                    .requestProfile()
                    .build();

            AppCompatActivity appCompatActivity = (AppCompatActivity) context;

            googleApiClient = new GoogleApiClient.Builder(context)
                    .enableAutoManage(appCompatActivity, this)
                    .addConnectionCallbacks(this)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .addApi(Plus.API)
                    .build();

I have also added "google-services.gson" file at app level. I have also made web-application and use client-id for requestIdToken() parameter.

requestIdToken(client-id of webapp).

After writing this code, Still I am getting status code = 12501 in response and tokenId = null.

I have also read this link. But Can not find any solution.

Community
  • 1
  • 1
Akashsingla19
  • 690
  • 2
  • 8
  • 18
  • We found the solution in [this post](http://stackoverflow.com/questions/33583326/new-google-sign-in-android) – Kaizie Jan 13 '16 at 16:35

3 Answers3

12

You need to add the credentials for both your signed and debug client_id in the google-services.json file like this:

"oauth_client": [
  {
    "client_id": "<your-client-id>",
    "client_type": 1,
    "android_info": {
      "package_name": "<your-package-name>",
      "certificate_hash": "<hash>"
    }
  },
   {
    "client_id": "<your-client-id-2>",
    "client_type": 1,
    "android_info": {
      "package_name": "<your-package-name-2>",
      "certificate_hash": "<hash-2>"
    }
  }
]
gerardnimo
  • 1,444
  • 8
  • 10
  • You may also want to double check the clientIds that you used and a possiblility of mismatch in package name. I'm not sure if this [reference](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes#constants) will help you, but I'll paste it anyway. – gerardnimo Jan 05 '16 at 04:47
  • Those two client ids are the one you obtained by using the debug keystore and the signed keystore. You may want to include both in your google-services.json file – gerardnimo Jan 05 '16 at 06:17
  • I want to know that client-id is android id or client-id is web application id? – Akashsingla19 Jan 05 '16 at 06:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/99766/discussion-between-akashsingla19-and-gerardnimo). – Akashsingla19 Jan 05 '16 at 06:25
  • @Akashsingla19 and gerard thanks, your chat and this above answer lead me to my solution; however I think there's a bit of a misdirected belief in the Web Client ID. I don't know how Android Studio auto-generates the Web Client ID, but it's not the same as the debug key in my google services console. An entry was auto-created by Android Studio for my debug key, in June, possibly corresponding to an upgrade I did to Android Studio, so maybe when you both were working through this, AS didn't automatically generate debug keys... continuing... – Tom Pace Dec 02 '16 at 01:03
  • I don't need back-end authentication. And I demanded there be zero server_client_id key in res/values/strings.xml because it wasn't part of the Google services setup documentation. I demanded to omit .requestIdToken(""). Finally have succeeded. The problem in my case is (and likely everyone else, somewhat), the GENERATOR for google-services.json only picks ONE access key, no option for extras?! AARGH. So I have two keys, and it picks the release one, so I must manually edit it, and it's not exactly dependant on Web Client ID. Just... need... the second json entry. THANK YOU gerardnimo. :) – Tom Pace Dec 02 '16 at 01:07
  • oops, made a minor mistake above: In June, a second *non Web client* key was auto-generated by AS, but it was my release key. That's when I released the app, but the debug key auto-generated earlier. Extra reasons around that, and possibly because "I upgraded AS". So ignore the "upgrade AS" and "auto-create two keys release/debug at same time" points. It is just an issue with the generator. – Tom Pace Dec 02 '16 at 01:28
  • ... I'm done with commenting on this, just want to say, now repeatedly testing in the last hour, the services config page and generator have made a liar out of me. For some reason.. NOW, *after* doing my modification to the two non-Web-client-ids in Console/Creds/OAuth2, two sha1 signatures are appearing. It is exhausting. Almost as bad as Facebook's docs and SDK. – Tom Pace Dec 02 '16 at 01:49
0

This may be due to Sha-1 and Sha-256 release and debug key mismatch.

Add all three(Debug: Sha-1, Release: Sha-1 and Sha-256) keys into the firebase console then re-download the json and replace.

It works fine for me.

Some times the OAuth 2.0 client IDs(Web application key) may be mismatched

0

Make sure that you include the following in your manifest file:

<application ...>

    <meta-data
        android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />  <!-- if app is a game -->

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
Cengiz
  • 1
  • 1