Google SignIn拒绝使用Firebase

拉维·基纳克

该应用程序说,即使从firebase授予了权限,身份验证仍失败了(haha)请在下面查看我的主要活动。在教程中,登录代码是不同的,我想是老的,我在firebase中添加了sha1,并且gradle完美连接。在firebase和developer.google上描述的命令很少使人困惑。请帮忙!在2周前启动android。

import android.content.Intent;   
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;

public class MainActivity extends AppCompatActivity implements           View.OnClickListener {

private static final int RC_SIGN_IN = 123;
private static final String TAG = "Play";
GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    mAuth = FirebaseAuth.getInstance();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
    findViewById(R.id.sign_in_button) .setOnClickListener(this);
}

@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    //updateUI(currentUser);
}


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


private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "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) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        Toast.makeText(MainActivity.this, "Welcome",
                                Toast.LENGTH_SHORT).show();
                        //updateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(MainActivity.this, "haha",
                                Toast.LENGTH_SHORT).show();
                        //updateUI(null);
                    }

                    // ...
                }
            });
}




@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) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
            // ...
        }
    }
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.sign_in_button:
            signIn();
            break;

}
}}       
哈里库玛·阿兰格德(Harikumar Alangode)

这可能是由于错误的客户ID

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id)) // here
            .requestEmail()
            .build();

您只能通过“凭据”选项从Google开发人员控制台获取服务器的客户端ID:https//console.developers.google.com/

另一件事是检查是否在Firebase控制台->身份验证中启用了通过Google身份验证

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 Google SignIn 的 Firebase WebApp 仅适用于特定域和特定用户

如何确定用户之前是否已使用 google firebase signin 登录

FIrebase Google Auth 注销错误连接被拒绝

在iOS中使用Google SignIn后无法获取Authcode(Swift)

使用AWS Cognito进行react-native-google-signin

使用Firebase与Google登录

VerifyError:验证者使用Gradle插件3.2.0 + Proguard拒绝了日志com.google.firebase.FirebaseApp类

如何同时使用Polymer的google-client-loader和google-signin?

iOS CocoaPod警告-使用Pod“ Google / SignIn”时,“ Google已被弃用”

为什么安装Google SignIn SDK会安装Firebase-可可豆荚

如何知道用户是刚刚创建还是已经存在 google signin 和 firebase web 9?

pod“ Google / SignIn”与pod“ GoogleSignIn”

使用Google SDK v3.x从App Store拒绝Google +登录iOS App拒绝

google登录,无需使用firebase

ITMS-90535无法使用最新的Google Signin SDK发布iOS应用

我可以在整个应用程序中使用Google SignIn令牌吗?

如何使用重定向模式(无弹出窗口)从 Google Signin 获取个人资料信息?

使用 Unity 构建此 ios 项目,添加了 google signin SDK 4.0.1 框架,出现错误

如何使用Typescript在Angular 2中用Google实现SignIn

使用带有自定义域的react-native-google-signin

苹果因使用Google Maps SDK而拒绝了该应用

google-signin不返回用户信息

任务com.google.firebase.av从java.util.concurrent.ThreadPoolExecutor中拒绝

Google Cloud SCP权限被拒绝

应用因Google Pay而被拒绝

Google Play拒绝Android应用

Google/Firebase android SDK 是否使用 GRPC?

使用 Firebase 登录 Google 不起作用

使用Google Apps脚本从Firebase读取数据...