简体   繁体   English

com.google.android.gms.common.api.ApiException: 10:

[英]com.google.android.gms.common.api.ApiException: 10:

I want do Google SignIn using below gradle.我想使用以下 gradle 进行 Google SignIn。

implementation 'com.google.android.gms:play-services-auth:15.0.0'

Below code for initialisation :下面的初始化代码:

private fun initGooglePlus() {
        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.server_client_id))
                .requestEmail()
                .build()
        mGoogleSignInClient = GoogleSignIn.getClient(this.activity!!, gso)
    }

I am calling below code in my button click我在我的按钮点击中调用下面的代码

private fun googlePlusLogin() {
        val signInIntent = mGoogleSignInClient!!.signInIntent
        startActivityForResult(signInIntent, SIGN_IN_CODE)
    }

OnActivityForResult活动结果

override
    fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == SIGN_IN_CODE) {
            val task = GoogleSignIn.getSignedInAccountFromIntent(data)
            handleSignInResult(task)
        }  
    }

I am getting below exception in onActivityForResult :我在 onActivityForResult 中遇到以下异常:

com.google.android.gms.common.api.ApiException: 10: 
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)

I have tried both Android Auth key and Web Auth key.我已经尝试了 Android Auth 密钥和 Web Auth 密钥。 I am always getting above exception.我总是超越例外。

Please help me out.请帮帮我。

This exception code means configuration problems with your app.此异常代码表示您的应用程序存在配置问题 I was having the same problem, and it was solved, for me, this way (in my case, I wanted firebase authentication with google sign in mechanism):我遇到了同样的问题,对我来说,它以这种方式解决了(就我而言,我想要使用 Google 登录机制进行 Firebase 身份验证):

  • I used a google automatically generated web client id instead of the one I had created (I didn't even ask google to generate it - it was really automatic)我使用了谷歌自动生成的网络客户端 ID 而不是我创建的(我什至没有要求谷歌生成它 - 它真的是自动的)
  • I updated my JSON firebase file in my android project (it's probably not necessary but I was running out of options)我在我的 android 项目中更新了我的 JSON firebase 文件(这可能没有必要,但我的选择用完了)
    An observation that may be helpful:一个可能有帮助的观察:
  • If you have a line like this...如果你有这样一条线...
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);

... probably you need Android auth ... 可能你需要 Android 身份验证

I will copy the important part of my code (it's working and written in Java), but I think, by your exception message, that there is nothing wrong with your code.我将复制我的代码的重要部分(它是用 Java 编写的),但我认为,根据您的异常消息,您的代码没有任何问题。

void onCreate(...) {
    firebaseAuth = FirebaseAuth.getInstance();
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.web_server_client_id))
            .requestEmail()
            .build();
    FirebaseUser currentUser = firebaseAuth.getCurrentUser();
    firebaseAuthUpdateUI(currentUser);

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

    findViewById(getLoginButtonId()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signIn();
        }
    });

}



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

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

    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
            // ...
            firebaseAuthUpdateUI(null);
        }


    }
}


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

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    firebaseAuth.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");
                        user = firebaseAuth.getCurrentUser();
                        firebaseAuthUpdateUI(user);
                    } else {
                        // If sign in fails, display a message to the user.
                        //Log.w(TAG, "signInWithCredential:failure", task.getException());
                        Toast.makeText(SignInActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                        user = null;
                        //firebaseAuthUpdateUI(null);
                    }

                    // ...
                }
            });
}

... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.google.android.gms.common.api.ApiException: 10 - com.google.android.gms.common.api.ApiException: 10 异常com.google.android.gms.common.api.ApiException:12500 - Exception com.google.android.gms.common.api.ApiException: 12500 com.google.android.gms.common.api.ApiException: 12500 - com.google.android.gms.common.api.ApiException: 12500 安全网:com.google.android.gms.common.api.ApiException:16: - SAFETYNET : com.google.android.gms.common.api.ApiException: 16: com.google.android.gms.common.api.ApiException: 16: - com.google.android.gms.common.api.ApiException: 16: com.google.android.gms.common.api.ApiException:8: - com.google.android.gms.common.api.ApiException: 8: 谷歌登录失败 com.google.android.gms.common.api.ApiException: 10: - Google sign in failed com.google.android.gms.common.api.ApiException: 10: com.google.android.gms.common.api.ApiException: 10: 调用者未列入白名单以调用此 API - com.google.android.gms.common.api.ApiException: 10: Caller not whitelisted to call this API 无法使用 Google Plus 登录,出现 com.google.android.gms.common.api.ApiException: 10: - Unable to login using Google Plus, getting com.google.android.gms.common.api.ApiException: 10: Flutter:Firebase:PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,null) - Flutter: Firebase: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM