Google SignIn API异常10 [英] Google SignIn API Exception 10

查看:1388
本文介绍了Google SignIn API异常10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在接近认证的最后阶段,但是handleSignInResult方法中出了点问题.它在日志中返回异常代码10(开发人员错误). Google提供了全面的描述:

Approaching to the final stage of the authentification, but something is going wrong in handleSignInResult method. It returns Exception code 10 (Developer error) in logs. Google provides comprehensive description:

该应用程序配置错误.该错误不可恢复,将被视为致命错误.开发人员是个白痴...

The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer is an idiot...

该如何处理(获取帐户)并最终从帐户中检索值?
预先感谢您的帮助!

What should I do to handle this (get an account) and finally retrive values from account?
Thank you in advance for your help!!!

MainActivity:

MainActivity:

package ru.podgorny.carcall;

import ...

public class MainActivity extends AppCompatActivity {

        SignInButton signInButton;
        public static final int RC_SIGN_IN = 07;
        public static final String TAG = "MainActivity";
        TextView tw1;
        TextView tw2;


        GoogleSignInOptions gso;
        GoogleSignInClient mGSC;


        @Override
        protected void onCreate (Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "Activity Works");
        findViews();

            gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    //.requestProfile()
                    .build();

            mGSC = GoogleSignIn.getClient(this, gso); //smth with mGSC variable....

             View.OnClickListener onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClick2(v);
                }
            };
             signInButton.setOnClickListener(onClickListener);




    }

    private void findViews() {
            Log.d (TAG, "findViews started");
        signInButton = findViewById(R.id.idButtonGoogle);

        tw1 = findViewById(R.id.textView1);
        tw1 = findViewById(R.id.textView2);

        Log.d(TAG, "Views finded");


    }

    public void onClick2(View view) {
            Log.d(TAG, "onClick started");
        switch (view.getId()) {
            case R.id.idButtonGoogle:
                signIn();
                break;
        }
        Log.d(TAG, "OnClick Started");
    }

    public void signIn() {

        Intent signInIntent = mGSC.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);
        Log.d(TAG, "startActivityForResult works");

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "OnActivityResult started");
        // 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.
            Log.d(TAG, "TASK started");
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            handleSignInResult(task);
            Log.d(TAG, "OnActivityResult returned");
        }
    }

    private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);//ERROR -- Code 10
            Log.d(TAG, "Account received");


            updateUI(account);
            Log.d(TAG, "updateUI Launched");
        } catch (ApiException e) {

            Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
            updateUI(null);
        }
    }

    private void updateUI(GoogleSignInAccount account) {
            if (account!=null) {
                tw1.setText("OK");
                tw2.setText("Name: " + account.getGivenName() + ", Family name: " + account.getFamilyName() + ", Email: " + account.getEmail() /*+ " image: " +
                        account.getPhotoUrl()*/);
            }else {
                tw1.setText("SMTH wrong");
            }

        }

}

推荐答案

如果您不在 console.developers.google console.firebase.google上使用同一项目,则可能会发生此错误. .com .如果两个控制台上的项目相同,请确保已正确添加 SHA1 键.从Android Studio获取 SHA1 .

This error might happen if you are not using same project at console.developers.google and console.firebase.google.com. If project is same at both console make sure you have add your SHA1 Key properly. Get SHA1 from Android studio.

  1. 打开Android Studio
  2. 打开您的项目
  3. 单击Gradle(在右侧面板中,您将看到Gradle Bar)
  4. 单击刷新(从Gradle Bar单击刷新,您将看到列出项目的Gradle脚本)
  5. 单击您的项目(您的项目名称表单列表(根))
  6. 单击任务
  7. 点击Android
  8. 双击signingReport(您将在运行栏中获得SHA1和MD5(有时将在Gradle控制台中获得)
  9. 从模块选择下拉列表中选择应用程序模块以运行或调试您的应用程序,还需要从firebase控制台获取google-services.json并将其放入您的项目中.

这篇关于Google SignIn API异常10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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