我正在使用此代码来使用Firebase的sigin。Firebase Google Sigin身份验证失败
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
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) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Toast.makeText(SignIn.this, "Authentication Went wrong ", Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.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("TAG", "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
//updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("TAG", "signInWithCredential:failure", task.getException());
Toast.makeText(SignIn.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
//updateUI(null);
}
// ...
}
});
}
} 但是,当我试图签署in.Like验证失败,它给错误。 我在哪里做错了?
我已经包括既为firebaseAuth的依赖关系里面我的应用摇篮 compile 'com.google.firebase:firebase-auth:11.0.2' compile 'com.google.android.gms:play-services-auth:11.0.2'
而且也使谷歌在我的火力地堡控制台登入方法。
在我的logout.class
我使用此代码`button =(Button)findViewById(R.id.logout); mAuth = FirebaseAuth.getInstance();
mAuthlistener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() == null) {
startActivity(new Intent(logout.this, SignIn.class));
}
}
};
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mAuth.signOut();
}
});
}`
但是当我点击那么这将打开Sigin.class
但是当我们再次尝试SIGIN崩溃。
好吧,我会让你知道 – DimKUsik
工作当我连接Firebase到Android Studio从工具选项,btw感谢您的帮助。 :) – DimKUsik
我还有一件事是面对注销按钮的问题当用户你可以你建议我一种方法。我在上面添加了我的注销代码。请检查 – DimKUsik