Firebase没有用户记录GoogleSingin

时间:2017-09-15 19:23:40

标签: java android firebase firebase-authentication google-signin

我正在使用Firebase Auth。我正在尝试使用 signInWithCredential 方法在拥有Google帐户的用户中唱歌。来自Google的凭证是可以的,但是当我尝试使用firebase登录用户时,我收到错误:

login error: signInWithCredential:failure com.google.firebase.auth.FirebaseAuthInvalidUserException: There is no user record corresponding to this identifier. The user may have been deleted. at com.google.android.gms.internal.zzdjy.zzak(Unknown Source:84) at com.google.android.gms.internal.zzdja.zza(Unknown Source:12)com.google.android.gms.internal.zzdki.zzal(Unknown Source:11)com.google.android.gms.internal.zzdkk.onFailure(Unknown Source:35)com.google.android.gms.internal.zzdka.onTransact(Unknown Source:79)android.os.Binder.execTransact(Binder.java:674)

如果我使用电子邮件和密码提供商而不是使用Google凭据在用户中唱歌,我会理解错误。

此错误来自一个新项目,因此没有用户进行过身份验证。

我已经尝试在gradle中更改了signedConfigs并更改了firebase控制台中的sha1键。多次删除项目,我似乎无法让它工作。

这很奇怪,因为我记得我过去没有遇到任何问题。

如果你不能帮助。谢谢。

来源:

private static final int RC_SIGN_IN = 1;
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mAuth = FirebaseAuth.getInstance();
    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();
    findViewById(R.id.sign).setOnClickListener(this);
}

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 {
            Log.d("login", "googleSignInRsult:error");
        }
    }
}

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()) {
                        Log.d("login", "signInWithCredential:success");
                    } else {
                        Toast.makeText(MainActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        Log.w("login", "signInWithCredential:failure", task.getException());
                    }
                }
            });
}

1 个答案:

答案 0 :(得分:0)

重新安装Android Studio,现在一切正常。