java - Android Google 登录失败 com.google.android.gms.common.api.ApiException: 12500
问题描述
因此,我正在尝试使用此链接提供的使用 Firebase 的 Google 登录身份验证: https ://firebase.google.com/docs/auth/android/google-signin?hl=en
我遵循了每一步,包括将我SHA-1 Fingerprint
的放入 firebase 项目。我目前处于调试模式,所以我只有一个SHA-1 Fingerprint
.
这是我的代码:
@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());
}
// ...
}
});
}
这是我得到的错误:
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)
我试图检查来自的 resultCodeSigningIntent
是否成功。事实证明我们不是Activity.RESULT_OK
。在登录窗口中选择帐户后,我立即收到错误消息。
我尝试过的解决方案:
- 将 Firebase Google 登录设置中的 Web 客户端 ID 更改为我在 Cloud Console 中的 Oath 凭据中的 ID
- 将我的 gms 服务库更新到最新版本(根据Google 登录错误 12500)
- 在我的 Cloud Console 中为 Android 创建 OAuth
这些都没有给我一个解决方案。我试图阅读文档以了解错误代码12500
的含义,但似乎没有具体原因。它说尝试使用另一封电子邮件,它仍然是一样的。
有人对此有任何解决方案吗?
解决方案
在 Play Store 中部署我的颤振应用程序进行内部测试并且生产密钥的 SHA-1 不起作用(生产密钥文件是新的)后,我遇到了这个问题。几天后我想通了 -我需要从Google Play 商店 > 发布管理 > 应用签名 > 应用签名证书添加 SHA-1 - SHA-1 证书指纹与本地密钥的 SHA-1 不同(此证书是在Google Play 商店 > 发布管理 > 应用签名 > 上传证书 - SHA-1 证书指纹中可见)
推荐阅读
- java - Java 11:错误:java:无效的源版本:11 - 不知道该怎么做
- c++ - 我在这个结构上做错了什么?
- nginx - Kubernetes 1.16.10 集群上的 Nginx 控制器升级失败
- c++ - 逐行读取文本文件并将其存储在数组中
- c# - 带有 unity.mvc 的 Identity AuthenticationManager
- google-apps-script - 当我将 GAS 项目作为附加组件进行测试时,触发器无法正常工作
- javascript - NodeJs 计划进程的最佳实践?
- reactjs - 如何从浏览器单击从 react-native-webview 访问下一个 url
- python - 如何将终端集成到使用 python-tk 创建的文本编辑器中?
- python - 如何抓取具有内部 iFrame 的 iFrame?