why is requestIdToken returning null?

In my case i had previously,

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

I fixed it by adding adding the requestToken method,

 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(getString(R.string.default_web_client_id))
            .build();

Now its working for me.Hopefully this can help somebody having issues like me.


As I have answered at the following question:

Google Sign-In requestIdToken returns null

In order to request Id Token sucessfully, you should use a "Web application" type Client Id, instead of "Android" type Client Id.

You also find at Google's documentation, the following info (please note #3):

Create an OAuth 2.0 client ID for your backend server

If your app authenticates with a backend server or accesses Google APIs from your backend server, you must create an OAuth 2.0 client ID for your server. To create an OAuth 2.0 client ID:

  1. Open the Credentials page.
  2. Click Add credentials > OAuth 2.0 client ID.
  3. Select Web application.
  4. Click Create.

Pass this client ID to the requestIdToken or requestServerAuthCode method when you create the GoogleSignInOptions object.


Update Mar 26:

Android Developers Blog - Registering OAuth clients for Google Sign-In