android - Firebase google SignIn 结果总是错误的?

标签 android firebase firebase-authentication google-signin

我正在尝试使用 Firebase google 登录方法注册我的应用程序。 googleSignInResult.isSuccess() 始终返回 false。我试着用谷歌搜索所有可能的网站。但是找不到我的代码有什么问题。

    googleSignInButton = (Button)findViewById(R.id.googleSignInButton);
    googleSignInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent googleSignInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            startActivityForResult(googleSignInIntent, RC_SIGN_IN);

        }
    });

处理结果的代码

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);



    if(requestCode == RC_SIGN_IN){

        mAuth = FirebaseAuth.getInstance();
        GoogleSignInResult googleSignInResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        Log.d(TAG , "Google signIn" + googleSignInResult.isSuccess() );
        if(googleSignInResult.isSuccess())
        {
            GoogleSignInAccount googleSignInAccount = googleSignInResult.getSignInAccount();
            AuthCredential accountAuthCredential = GoogleAuthProvider
                    .getCredential(googleSignInAccount.getIdToken(),null);
            mAuth.signInWithCredential(accountAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if(task.isSuccessful()){

                        Intent i = new Intent(getApplicationContext(), MainActivity.class);
                        startActivity(i);

                    }else{

                    }
                }
            });


        }else {


        }
    }
}

最佳答案

我有类似的问题。以下解决了它:

  1. 确保在 Firebase 项目设置中配置 SHA1
  2. 在 build.gradle (App) 中设置:

    apply plugin: 'com.android.application'

    在文件的开头和

    apply plugin: 'com.google.gms.google-services' at the end after dependencies {....}

    希望对您有所帮助

关于android - Firebase google SignIn 结果总是错误的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38100482/

相关文章:

java - Android 保存的图像质量低

java - 获取色轮java中两种颜色之间的差异

javascript - 更新 firebase 数据库中嵌套数组的值

android - 无法使用 Firebase Auth 添加 Firebase 数据库

firebase - 如何使用 Ionic 4 实现 Firebase 电话身份验证?

android - 在 Cygwin 中使用 repo 下载 Android 源码

Android 如何为自定义文件扩展名创建 Intent Filter,使其不成为手机上所有内容的选择器的一部分

reactjs - 如何使用 React 和 Firebase 托管在 SPA 上提供 robots.txt?

ios - Flutter:将 dsym 符号上传到带有风格的 Firebase crashlytics

ios - Auth.auth.currentUser.uid 即使登录有效也无法正常工作