2
votes

I created a project and a Android credentials in https://console.developers.google.com/apis/credentials?project=XXXXX

I'm following this steps to add Google SignIn on my Android app: https://developers.google.com/identity/sign-in/android/start-integrating#prerequisites

My first doubt is. How I can get the google-services.json file after credential is created on google console? I'm only able to download a client_secret_XXXXXXXXXXX-asdfasdfasdfasdfasdfasdf.apps.googleusercontent.com.json

After everything setup following the Google SignIn guide I can't get the token from Google API. I found this question: New Google sign in Android

The first step tells you to create the configuration file (which creates an OAuth 2.0 client ID for you and inserts it into the google-services.json)

Then later, it says again about creating a OAuth 2.0 client ID, but this time it says that you have to do it for Web application

And this is the confusing part! (at least for me) because i was just taking the client id created for the android OAuth and not creating a new one for Web application (I thought the documentation was just redundant or something)

As it says, it is this one, and only this one the one you have to use as a parameter of the methods requestIdToken or requestServerAuthCode.

Forget about using the Android OAuth ID in this methods because then you will get all the time the ugly status code response 12501.

I think the main problem is that the documentation is a bit confusing about this. Or maybe because it is a bit strange the fact that you have to create two OAuth IDs.

So as a summary, you need TWO OAuth IDs, one for android and one for web application, and you have to set each one in the correct place.

There says that I have to create a web application credential. Now I'm confused, I have 2 json files (client_secret_XXXXXXXXXXX-asdfasdfasdfasdfasdfasdf.apps.googleusercontent.com.json and google-services.json, and 2 Client ID (Android and Web)

    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    String serverClientId = getString(R.string.oauth_client_google);
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(serverClientId)
            .requestProfile()
            .build();
    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

R.string.oauth_client_google is the Web Application Client ID. If I set the Android Client ID there is not working.

Do I really need a Android Client ID?

Anyone knows the right steps to do to have: first the google account selector and then the token from google?

1
Thanks @steven following the link I could get the google-services.json again. But I still have the issue when I try to get the tokenId adding .requestIdToken(serverClientId) on GoogleSignInOptions. I have to use the Web Application Client ID to make it works instead of the Android Client ID That is very confuse..josealfonsomora

1 Answers

0
votes

Go to https://developers.google.com/identity/sign-in/android/start to configure and get google_services.json by following the steps.Everything is written over there clearly. client secret is not required. Keep that google_services.json file in your app folder.

And then in your activity declare

private GoogleApiClient mGoogleApiClient;

After that in onCreate method write

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
              .requestEmail()
              .build();

      mGoogleApiClient = new GoogleApiClient.Builder(this)
              .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
              .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
              .addApi(Plus.API)
              .build();

And proceed further following google document https://developers.google.com/identity/sign-in/android/sign-in#add_the_google_sign-in_button_to_your_app