首页 > 解决方案 > 我的 Google 登录在我的 Android 应用上运行良好,现在它给出了错误代码“10”

问题描述

我正在开发一个 Android 应用程序,并且 Google 登录运行得非常好。由于一些硬件问题,之后我不得不重新安装 Windows,当我尝试新的 APK 时,应用程序开始抛出错误,给出代码:10。

我尝试将新的 SHA-1 密钥上传到 Firebase 控制台。我什至创建了一个 Google Sign 运行良好的虚拟应用程序。

private GoogleSignInClient mGoogleSignInClient; //globally defined

在 onCreateMethod() 我正在使用这个

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();
        // [END config_signin]

        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
 @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


        if (requestCode == REQ_CODE) {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            handleSignInResult(task);
        }

    }

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);
            //login="2";
            // Signed in successfully, show authenticated UI.
            //updateUI(account);
            Log.i("Email", account.getEmail());
            Log.i("Display Name", account.getDisplayName());
            Log.i("First Name", account.getFamilyName());
            Log.i("Given Name", account.getGivenName());
            Log.i("Profile", account.getPhotoUrl().toString());
            Log.i("Token", account.getId());
            progressDialog.show();
            final Thread t = new Thread() {
                @Override
                public void run() {
                    int jumpTime = 0;
                    while (jumpTime < totalprogressTime) {

                        try {
                            sleep(3000
                            );
                            jumpTime += 5;
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }
            };
            t.start();
            GOOGLElogIn(account.getEmail(),"1",account.getDisplayName(),account.getIdToken(),logintype);
            //,login,
        } catch (ApiException e) {
            // The ApiException status code indicates the detailed failure reason.
            // Please refer to the GoogleSignInStatusCodes class reference for more information.
            Log.e("Google SignIn", "signInResult:failed code=" + e.getStatusCode());

            //show toast
            Toast.makeText(this, "Failed to do Sign In : " + e.getStatusCode(), Toast.LENGTH_SHORT).show();

            //updateUI(null);
        }
    }
go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isGuest=false;
                logintype = "3";
                Intent signInIntent = mGoogleSignInClient.getSignInIntent();
                startActivityForResult(signInIntent, REQ_CODE);
            }
        });

控制台日志显示此

D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=1110, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=4507256814460934916}]
V/FA: onActivityCreated
D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=LoginActivity, firebase_previous_id(_pi)=4507256814460934916, firebase_screen_class(_sc)=SignInHubActivity, firebase_screen_id(_si)=4507256814460934917}]
V/FA: Activity resumed, time: 620052166
    Screen exposed for less than 1000 ms. Event not sent. time: 97
V/FA: Activity paused, time: 620052199
E/Google SignIn: signInResult:failed code=10

标签: androidgoogle-signin

解决方案


根据@IntelliJ Amiya github 链接,它显示错误代码 10 是 DEVELOPER_ERROR。

您需要检查 3 个问题

  1. Google API 控制台中的 SHA1 和包名称
  2. 检查 GoogleSignInOptions
  3. Web 客户端 ID(如果您正在使用它)属于您注册包名称和 SHA1 的同一个项目。

推荐阅读