简体   繁体   English

Android Google 登录失败 com.google.android.gms.common.api.ApiException: 12500

[英]Android Google Sign In Failed com.google.android.gms.common.api.ApiException: 12500

So I'm trying to use Google Sign In Authentication using Firebase as provide by this link : https://firebase.google.com/docs/auth/android/google-signin?hl=en因此,我正在尝试使用此链接提供的 Firebase 使用 Google 登录身份验证: https ://firebase.google.com/docs/auth/android/google-signin ?hl= en

I followed every single step including putting my SHA-1 Fingerprint into the firebase project.我遵循了每一步,包括将我的SHA-1 Fingerprint放入 firebase 项目。 I'm currently on debug mode so I only have one SHA-1 Fingerprint .我目前处于调试模式,所以我只有一个SHA-1 Fingerprint

Here's my code:这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

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

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);


    mAuth = FirebaseAuth.getInstance();

    LinearLayout gLog = (LinearLayout) findViewById(R.id.googleLogin);
    gLog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            signIn();
        }
    });

}

private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w("Error", "Google sign in failed", e);
            // ...
        }
    }
}

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d("Akun", "firebaseAuthWithGoogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d("MsgFirebase", "signInWithCredential:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        Intent i = new Intent(login_activity.this, main_activity.class);
                        i.putExtra("nama", user.getDisplayName());
                        i.putExtra("email", user.getEmail());
                        startActivity(i);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w("MsgFirebase", "signInWithCredential:failure", task.getException());
                    }

                    // ...
                }
            });
}

And here's the error that I got :这是我得到的错误:

com.google.android.gms.common.api.ApiException: 12500: 
    at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
    at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
    at com.mfs.rumah_duka.login_activity.onActivityResult(login_activity.java:112)
    at android.app.Activity.dispatchActivityResult(Activity.java:6562)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3752)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3799)
    at android.app.ActivityThread.access$1500(ActivityThread.java:154)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5555)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:118)

I tried to check if the resultCode from the SigningIntent is success.我试图检查来自SigningIntent的 resultCode 是否成功。 It turns our it's not Activity.RESULT_OK .它变成了我们的它不是Activity.RESULT_OK I got the error right after I choose an account on the Sign In window.在“登录”窗口中选择一个帐户后,我立即收到错误消息。

Solutions that I've tried :我尝试过的解决方案:

  • Changed web client ID in the Firebase Google Sign In setting to the one from my Oath credential in my Cloud Console将 Firebase Google 登录设置中的 Web 客户端 ID 更改为 Cloud Console 中我的 Oath 凭据中的那个
  • Updated my gms service library to the latest version (According to Google Sign In error 12500 )将我的 gms 服务库更新到最新版本(根据Google 登录错误 12500
  • Create an OAuth for Android in my Cloud Console在我的 Cloud Console 中为 Android 创建 OAuth

None of those gave me a solution.这些都没有给我一个解决方案。 I tried to read the documentation as to what error code 12500 means but it seems there's no specific cause.我试图阅读文档以了解错误代码12500含义,但似乎没有具体原因。 It says that try to use another email and it's still the same.它说尝试使用另一封电子邮件,它仍然是一样的。

Does anybody has any solution to this?有没有人对此有任何解决方案?

I have faced the issue after deploying my flutter app in Play Store for internal testing and SHA-1 for production key was not working (production key file was new).在 Play 商店中部署我的 flutter 应用程序进行内部测试后,我遇到了这个问题,并且生产密钥的 SHA-1 不起作用(生产密钥文件是新的)。 After a few days I have figured it out - I needed to add SHA-1 from Google Play Store > Release management > App Signing > App signing certificate - SHA-1 certificate fingerprint which is different to local key's SHA-1 (this cert is visible in Google Play Store > Release management > App Signing > Upload certificate - SHA-1 certificate fingerprint )几天后我想通了 -我需要从Google Play 商店 > 发布管理 > 应用签名 > 应用签名证书添加 SHA-1 - SHA-1 证书指纹,它不同于本地密钥的 SHA-1(这个证书是在Google Play 商店中可见> 发布管理 > 应用签名 > 上传证书 - SHA-1 证书指纹

I faced the exact same issue.我遇到了完全相同的问题。 This is what I did.这就是我所做的。 First of all I ensured that I have latest google-services.json file in my project.首先,我确保我的项目中有最新的google-services.json文件。 Then I checked that the string key that I pass into the GoogleSignInOptions builder matches with the OAuth web client key in the GCP console.然后我检查了我传递到GoogleSignInOptions构建器的字符串键是否与GCP控制台中的OAuth Web 客户端键匹配。

Lastly, I updated my Google Play Services and the Google Repository (from the SDK Manager) to the latest version.最后,我将我的Google Play 服务Google 存储库(来自 SDK 管理器)更新到了最新版本。

Updating the Google Repository seems to have done the trick for me.更新 Google 存储库似乎对我有用。

When your app authenticates with a backend server or accesses Google APIs from your backend server, then you must pass the OAuth 2.0 client ID that was created for your server to the requestIdToken method when you construct the GoogleSignInOptions object, for accessing the user's basic profile information.当您的应用通过后端服务器进行身份验证或从后端服务器访问 Google API 时,您必须在构建 GoogleSignInOptions 对象时将为您的服务器创建的 OAuth 2.0 客户端 ID 传递给 requestIdToken 方法,以访问用户的基本个人资料信息. Also, don't forget to submit the support email in the OAuth consent screen found in the Credentials page in the API Console.此外,不要忘记在 API 控制台的凭据页面中的 OAuth 同意屏幕中提交支持电子邮件。

尝试将您的 Google Play 服务更新到最新版本,这可能会解决您的问题。

I was getting this error but when added details for OAuth consent screen in the api console - google login started working fine我收到此错误,但是当在 api 控制台中添加 OAuth 同意屏幕的详细信息时 - 谷歌登录开始正常工作在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谷歌玩服务游戏signInSilently()失败错误'com.google.android.gms.common.api.ApiException:4:4' - Google play service game signInSilently() FAILED error 'com.google.android.gms.common.api.ApiException: 4: 4 ' 带有com.google.android.gms.common.api.ApiException的Google Awareness API位置:7508 - Google Awareness API Places with com.google.android.gms.common.api.ApiException: 7508 Google Play 服务游戏无提示登录错误 &#39;com.google.android.gms.common.api.ApiException: 4:&#39; - Google play service game Silent Login error 'com.google.android.gms.common.api.ApiException: 4: ' Unhandled Exception: PlatformException (sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) - works well in one system - Unhandled Exception: PlatformException (sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) - works well in one system 获取自动完成预测 API 调用时出错:com.google.android.gms.common.api.ApiException: 9003: PLACES_API_ACCESS_NOT_CONFIGURED - Error getting autocomplete prediction API call: com.google.android.gms.common.api.ApiException: 9003: PLACES_API_ACCESS_NOT_CONFIGURED 无法实例化com.google.android.gms.common.SignInButton - Failed to instantiate com.google.android.gms.common.SignInButton IllegalArgumentException:接收者未注册:com.google.android.gms.common.api - IllegalArgumentException: Receiver not registered: com.google.android.gms.common.api 解析失败:Lcom/google/android/gms/common/api/Api$zzf; - Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf; 将Snapshot API与Android App集成会导致com.google.android.gms.common.api.ResolvableApiException:4:4: - Integrating Google Snapshot API to Android App causes in com.google.android.gms.common.api.ResolvableApiException: 4: 4: 程序类型已存在:com.google.android.gms.common.api.internal.zzd / android studio - Programm type already exist: com.google.android.gms.common.api.internal.zzd /android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM