且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

状态代码12501通过Google登录进行身份验证

更新时间:2023-12-01 10:35:58

您需要为签名和调试 client_id google-services.json 这样的文件: 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>
}
}
]


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.

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