Google 登录失败 com.google.android.gms.common.api.ApiException: 10: [英] Google sign in failed com.google.android.gms.common.api.ApiException: 10:

查看:155
本文介绍了Google 登录失败 com.google.android.gms.common.api.ApiException: 10:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我被这个令人沮丧的问题困住了.我对 Firebase 上的 Google 身份验证很陌生,但我已按照 firebase 文档中有关如何集成 Google 登录身份验证的说明完成了所有工作,但我仍然在控制台中收到这个奇怪的错误,该错误由两部分组成:

12-03 11:07:40.090 2574-3478/com.google.android.gms E/TokenRequestor: OAuth2相关配置有误,请检查.详细错误:UNREGISTERED_ON_API_CONSOLE

还有

Google 登录失败 com.google.android.gms.common.api.ApiException: 10:

在任何人试图指出以前在堆栈溢出时被问到的类似问题之前,这是我在看到所有可用的解决方案后到目前为止所做的,但尚未解决错误

  • 我有我的项目的 SHA1 指纹
  • 我有我的 OAuth 2.0 客户端 ID,包括 android 客户端 ID 和 Web 客户端,并且在 requestIdToken() 中我已经输入了 Web 客户端 ID.
  • 没有在 Google Play 商店发布我的项目的 APK.这意味着我没有意外生成另一个 SHA1 指纹.
  • 我已逐步遵循 Google 登录身份验证 firebase 文档.

这是我的代码片段:

@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_signup);ButterKnife.bind(this);String webClientId = getString(R.string.web_client_id);GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(webClientId).建造();mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this/* FragmentActivity */, this/* OnConnectionFailedListener */).addApi(Auth.GOOGLE_SIGN_IN_API, gso).建造();mGoogleSignInClient = GoogleSignIn.getClient(this, gso);GoogleSignInAccount 帐户 = GoogleSignIn.getLastSignedInAccount(this);googleLoginBtn.setOnClickListener(new View.OnClickListener() {@覆盖公共无效onClick(查看视图){意图 signInIntent = mGoogleSignInClient.getSignInIntent();startActivityForResult(signInIntent, RC_SIGN_IN);}});}@覆盖public void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);//从 GoogleSignInClient.getSignInIntent(...); 启动 Intent 返回的结果;如果(请求代码 == RC_SIGN_IN){//这个调用返回的Task总是完成的,不需要attach//一个监听器.任务任务 = GoogleSignIn.getSignedInAccountFromIntent(data);尝试{GoogleSignInAccount account = task.getResult(ApiException.class);firebaseAuthWithGoogle(帐户);} catch (ApiException e) {//Google 登录失败,适当更新 UILog.w(TAG, "谷歌登录失败", e);//[START_EXCLUDE]Toast.makeText(this, "Gooogle Auth failed", Toast.LENGTH_LONG);//[END_EXCLUDE]}}}private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());//[START_EXCLUDE 静音]//showProgressDialog();//[END_EXCLUDE]AuthCredential 凭证 = GoogleAuthProvider.getCredential(acct.getIdToken(), null);mAuth.signInWithCredential(凭证).addOnCompleteListener(this, new OnCompleteListener() {@覆盖public void onComplete(@NonNull Task task) {如果(任务.isSuccessful()){//登录成功,使用登录用户信息更新UILog.d(TAG, "signInWithCredential:success");FirebaseUser 用户 = mAuth.getCurrentUser();Toast.makeText(LoginActivity.this, "Successful Auth", Toast.LENGTH_LONG).show();} 别的 {//如果登录失败,向用户显示一条消息.Log.w(TAG, "signInWithCredential:failure", task.getException());Toast.makeText(LoginActivity.this, "身份验证失败.",Toast.LENGTH_SHORT).show();//更新UI(空);}//[START_EXCLUDE]//隐藏进度对话框();//[END_EXCLUDE]}});}

解决方案

基本上问题出在 SHA1 键放在控制台上,请重新生成它并重新正确放置相同的项目.

1) 作为答案,请确保您实际签名的 Android apk 具有与您在 Firebase 项目的 Android 集成部分的控制台中指定的相同的 SHA1 指纹(您可以下载 google-services.json 的页面)

更多信息,请参见:

So I'm Stuck on this frustrating issue. I am quite new to Google Auth on Firebase but I done everything the firebase docs instructed in how to integrate the Google SignIn Auth, yet I'm still receiving this weird Error in the console consisted of two parts:

12-03 11:07:40.090 2574-3478/com.google.android.gms E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE

and also

Google sign in failed com.google.android.gms.common.api.ApiException: 10:

Before Anyone attempts to point out similar questions that have previously been asked on stack overflow, Here's what I have done till now after seen all the available solutions and yet non has resolved the error

  • I have my SHA1 fingerprint for my project
  • I have my OAuth 2.0 client ID, both, the android client id and the web client and in the requestIdToken() I have put the web client id.
  • I did not publish my project's APK on google play store. which means I did not accidentally generate another SHA1 fingerprint.
  • I have followed step by step the Google Sign in Auth firebase docs.

here is my code snippet:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);
    ButterKnife.bind(this);

    String webClientId = getString(R.string.web_client_id);


    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(webClientId)
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);


    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);


    googleLoginBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent signInIntent = mGoogleSignInClient.getSignInIntent();
            startActivityForResult(signInIntent, RC_SIGN_IN);
        }
    });

}



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

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

        try{

            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);
            // [START_EXCLUDE]
            Toast.makeText(this, "Gooogle Auth failed", Toast.LENGTH_LONG);
            // [END_EXCLUDE]
        }

    }
}



private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    //showProgressDialog();
    // [END_EXCLUDE]

    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(LoginActivity.this, "Successful Auth", Toast.LENGTH_LONG).show();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        //updateUI(null);
                    }

                    // [START_EXCLUDE]
                    //hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}

解决方案

Basically problem is in the SHA1 key put on console please regenerate it and put again properly same project.

1)As the answers, make sure that your actual signed Android apk has the same SHA1 fingerprint as what you specified in the console of your Firebase project's Android integration section (the page where you can download the google-services.json)

For more info, see: Generate SHA-1 for Flutter app

2)On top of that go to the Settings of your firebase project (gear icon right to the Overview at the top-left area. Then switch to Account Linking tab. On that tab link the Google Play to your project.

EDIT: Account Linking tab doesn't exist any more, instead :

  1. Sign in to Firebase.
  2. Click the Settings icon, then select Project settings.
  3. Click the Integrations tab.
  4. On the Google Play card, click Link.

这篇关于Google 登录失败 com.google.android.gms.common.api.ApiException: 10:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆