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

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

问题描述

所以我对这个令人沮丧的问题感到困惑. 我是Firebase上的Google Auth的新手,但是我完成了Firebase文档指示的如何集成Google SignIn Auth的所有工作,但是我仍然在控制台中收到这个奇怪的错误,该错误由两部分组成:

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

还有

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

在任何人尝试指出以前在堆栈溢出时曾被问到的类似问题之前,这是我在看到所有可用解决方案之后仍未解决错误的方法

  • 我有我的项目的SHA1指纹
  • 我有我的OAuth 2.0客户端ID,包括android客户端ID和Web客户端,在requestIdToken()中,我已放置了 Web客户端ID .
  • 我没有在Google Play商店上发布我的项目的APK.这意味着我没有意外生成另一个SHA1指纹.
  • 我已逐步跟踪Google Sign in Auth firebase文档.
  • 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.

这是我的代码段:

@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]
                }
            });
}

推荐答案

基本上问题在于控制台上的SHA1键,请重新生成它,然后再次正确地放置同一项目.

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

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

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)

有关更多信息,请参见:为Flutter应用生成SHA-1

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

2)首先,转到您的Firebase项目的设置"(齿轮图标在左上角概述"的右侧.然后切换到帐户链接"标签.在该标签上,将Google Play链接到您的项目.

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.

帐户链接标签不再存在:

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

  1. 登录到Firebase.
  2. 单击设置"图标,然后选择项目设置".
  3. 单击集成"选项卡.
  4. 在Google Play卡上,单击Link.
  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天全站免登陆