所以我正在尝试使用此链接提供的使用 Firebase 的 Google 登录身份验证: https://firebase.google.com/docs/auth/android/google-signin?hl=en
我遵循了每一个步骤,包括将我的 SHA-1 Fingerprint
放入 firebase 项目中。我目前处于 Debug模式,所以我只有一个 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)
我尝试检查 SigningIntent
的 resultCode 是否成功。它变成了我们的它不是 Activity.RESULT_OK
。
我在“登录”窗口中选择帐户后立即收到错误消息。
我尝试过的解决方案:
- 将 Firebase Google 登录设置中的网络客户端 ID 更改为 一个来 self 的 Cloud Console 中的 Oath 凭证
- 将我的 gms 服务库更新到最新版本(根据 Google Sign In error 12500 )
- 在我的 Cloud Console 中为 Android 创建 OAuth
这些都没有给我解决方案。我试图阅读有关错误代码 12500
含义的文档,但似乎没有具体原因。它说尝试使用另一个电子邮件,它仍然是一样的。
有人对此有任何解决方案吗?
最佳答案
在 Play Store 中部署我的 flutter 应用程序进行内部测试后,我遇到了这个问题,生产 key 的 SHA-1 不起作用(生产 key 文件是新的)。几天后我弄明白了 - 我需要从 Google Play Store > Release management > App Signing > App signing certificate - SHA-1 certificate fingerprint 添加 SHA-1 这与本地 key 的 SHA-1 不同(此证书在 Google Play Store > Release management > App Signing > Upload certificate - SHA-1 certificate fingerprint 中可见)
关于java - Android Google 登录失败 com.google.android.gms.common.api.ApiException : 12500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54194066/