Firebase Auth与谷歌不工作。

时间:2022-05-20 20:56:26

I have gone through almost all the firebase google authentication questions on SO but still I am not able to find the solution to my issue.

我已经检查了几乎所有的firebase谷歌身份验证问题,但仍然无法找到问题的解决方案。

Here is my code for Firebase Google Authentication

这是我的Firebase谷歌认证代码

Inside onCreate

在onCreate

   GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .build();
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                        @Override
                        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

                        }
                    })
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .build();

            mAuth = FirebaseAuth.getInstance();

findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                signIn();
            }
        });

MethodToSignIn

MethodToSignIn

private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

onActivityResult

onActivityResult

@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 {
                // Google Sign In failed, update UI appropriately
                // ...
            }
        }
    }

FirebaseAuthWithGoogle

FirebaseAuthWithGoogle

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
        Log.d("MainACtivity", "firebaseAuthWithGoogle:" + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d("Main", "signInWithCredential:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Log.w("MainAcitivyt", "signInWithCredential", task.getException());
                            Toast.makeText(MainActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }
                        // ...
                    }
                });
    }

activity_welcome.xml

activity_welcome.xml

<com.google.android.gms.common.SignInButton
        android:id="@+id/sign_in_button"
        android:layout_width="wrap_content"
        android:layout_below="@+id/buttonSendData"
        android:layout_height="wrap_content" />

When I click on the Button I get the following in logcat and the app freezes

当我点击按钮时,我在logcat中得到了下面的内容,应用程序就会冻结

 D/ActivityThreadInjector: clearCachedDrawables.
     V/FA: Using measurement service
     V/FA: Connection attempt already in progress
     V/FA: Using measurement service
     V/FA: Connection attempt already in progress
     V/FA: Activity resumed, time: 285185857
     D/FA: Connected to remote service
     V/FA: Processing queued up service tasks: 3
     V/FA: Inactivity, disconnecting from the service
     V/FA: Connecting to remote service
     V/FA: Activity paused, time: 285382455
     D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=10085, _sc=SignInHubActivity, _si=3238861053606655861}]
     V/FA: Using measurement service
     V/FA: Connection attempt already in progress
     D/FA: Connected to remote service
     V/FA: Processing queued up service tasks: 2
     V/FA: Inactivity, disconnecting from the service

Firebase Auth与谷歌不工作。

1 个解决方案

#1


1  

Specify your app's SHA-1 fingerprint from your project settings in the firebase console. Enable google login in the sign-in method.Try the lastest dependencies also.

在firebase控制台从项目设置中指定应用程序的SHA-1指纹。在登录方法中启用谷歌登录。还可以尝试最新的依赖项。

#1


1  

Specify your app's SHA-1 fingerprint from your project settings in the firebase console. Enable google login in the sign-in method.Try the lastest dependencies also.

在firebase控制台从项目设置中指定应用程序的SHA-1指纹。在登录方法中启用谷歌登录。还可以尝试最新的依赖项。