Status code 12501 authenticating with google sign-

2020-04-07 05:34发布

问题:

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.

回答1:

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>"
    }
  }
]


回答2:

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



回答3:

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" />