gpt4 book ai didi

android - Firebase 身份验证无法使用 Google 登录

转载 作者:搜寻专家 更新时间:2023-11-01 09:38:11 24 4
gpt4 key购买 nike

我已经解决了几乎所有关于 SO 的 firebase google 身份验证问题,但我仍然无法找到问题的解决方案。

这是我的 Firebase Google 身份验证代码

onCreate

   GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

mAuth = FirebaseAuth.getInstance();

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

登录方法

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

onActivityResult

@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) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed, update UI appropriately
// ...
}
}
}

FirebaseAuthWithGoogle

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d("MainACtivity", "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) {
Log.d("Main", "signInWithCredential:onComplete:" + task.isSuccessful());

// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w("MainAcitivyt", "signInWithCredential", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}

activity_welcome.xml

<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_below="@+id/buttonSendData"
android:layout_height="wrap_content" />

当我点击按钮时,我在 logcat 中得到以下信息并且应用程序卡住

 D/ActivityThreadInjector: clearCachedDrawables.
V/FA: Using measurement service
V/FA: Connection attempt already in progress
V/FA: Using measurement service
V/FA: Connection attempt already in progress
V/FA: Activity resumed, time: 285185857
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 3
V/FA: Inactivity, disconnecting from the service
V/FA: Connecting to remote service
V/FA: Activity paused, time: 285382455
D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=10085, _sc=SignInHubActivity, _si=3238861053606655861}]
V/FA: Using measurement service
V/FA: Connection attempt already in progress
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 2
V/FA: Inactivity, disconnecting from the service

enter image description here

最佳答案

从项目设置中指定应用的 SHA-1 指纹 火力控制台。在登录方法中启用谷歌登录。也尝试最新的依赖项。

关于android - Firebase 身份验证无法使用 Google 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41527001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com