我正在使用此代碼來使用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