1
Firebase와 Google 계정으로 내 앱 인증을 시도했습니다. 공식 자습서를 읽고 Google 로그인 버튼을 선택하면 계정 목록이 표시되고 그 중 하나를 선택하여 가져옵니다. onActivityResult 메소드의 메시지를 기록하십시오. onActivityResult가 실패했습니다 - Google Auth Firebase
GoogleSignInOptions googleSignInOptions = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("here is my client id")
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed: failed");
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
mGoogleSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onClick:");
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
그리고에서 onCreate 방법 밖에
:@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Log.d(TAG, "onActivityResult: requestCode = " + requestCode);
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
Log.d(TAG, "onActivityResult: successful");
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Toast.makeText(getApplicationContext(), "Sign In Failed", Toast.LENGTH_LONG).show();
Log.d(TAG, "onActivityResult: failed");
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
Log.d(TAG, "firebaseAuthWithGoogle: " + account.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mFirebaseAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "onComplete: successful");
FirebaseUser user = mFirebaseAuth.getInstance().getCurrentUser();
Intent intent = new Intent(getApplicationContext(), HomeTabActivity.class);
startActivity(intent);
} else {
// If sign in fails, display a message to the user.
Log.d(TAG, "signInWithCredential:failure" + task.getException());
Toast.makeText(getApplicationContext(), "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
로보세요! 이것이 심각한 무엇인가를위한 것이라면 나는 그들을 지금 순환시킬 것입니다, 누군가는 그것들을 복사 할 수있었습니다! –
'GoogleSignInResult' 코드를 기록 할 수 있습니까? –
@FrankvanPuffelen 편집하기 전에 dev 키가 코드에있는 것처럼 보였습니다. 실제로는 클라이언트 ID 일뿐입니다. 그것은 사적인 것 같았다. –