简体   繁体   English

Firebase没有用户记录GoogleSingin

[英]Firebase There is no user record GoogleSingin

I am using Firebase Auth. 我正在使用Firebase Auth。 I am trying to sing in a user with Google Account, using the signInWithCredential method. 我正在尝试使用signInWithCredential方法在具有Google帐户的用户中唱歌。 The credential from Google are ok, but when I try to sign in the user with firebase i get an error: 来自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)

I would understand the error if i would be singing in the user with email and password provider not with Google credentials. 如果我要使用电子邮件和密码提供者而不是Google凭据在用户中唱歌,我会理解该错误。

And this error is from a new project so no users were ever authenticated. 而且此错误来自新项目,因此没有用户经过身份验证。

I allready tried changing signingConfigs in gradle and changing the sha1 keys in firebase console. 我已经尝试过在gradle中更改signingConfigs并在firebase控制台中更改sha1键。 Deleted the project multiple times and i cant seem to get it to work. 多次删除了该项目,我似乎无法正常工作。

It's weird because i remember that i had no problems in the past with this. 这很奇怪,因为我记得过去我对此没有任何问题。

Help if you cant. 如果您不能帮助。 Thank you. 谢谢。

Source: 资源:

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());
                    }
                }
            });
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM