我遇到了问题 我有一个使用Firebase Auth登录Google的应用。我将发布APK作为Alpha版本上传到Google Play商店,但是当我下载它以在手机上测试它时会出现身份验证错误,但是,当我从计算机下载相同的apk到我的手机时,它运行正常。
在我的主
中 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mAuth = FirebaseAuth.getInstance();
findViewById(R.id.signIn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
的
onStart:
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser!=null)
{
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}
的
的
的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);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Toast.makeText(LoginActivity.this, "Authentication failed, please try again",
Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
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()) {
FirebaseUser user = mAuth.getCurrentUser();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
} else {
// If sign in fails, display a message to the user.
System.out.println(task.getResult().toString());
Toast.makeText(LoginActivity.this, "Authentication failed, please try again",
Toast.LENGTH_SHORT).show();
}
}
});
}
的
答案 0 :(得分:3)