如何在Android中正确设置Google Play登录? [英] How to properly setup google play signin in Android?

查看:767
本文介绍了如何在Android中正确设置Google Play登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用android开发了一个游戏.我尝试实现GooglePlay登录,但显示错误.我无法调试此错误.我尝试在模拟器以外的其他手机型号上安装该应用程序.

I developed a game in android. I tried to implement the GooglePlay SignIn but it shows an error. I'm not able to debug this error. I tried installing the app in different phone models other than emulators.

代码:

public void startSignInIntent() {     
    startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

        if (requestCode == RC_SIGN_IN) {

            Task<GoogleSignInAccount> task =
                    GoogleSignIn.getSignedInAccountFromIntent(intent);

            try {
                GoogleSignInAccount account = task.getResult(ApiException.class);
            } catch (ApiException apiException) {
                String message = apiException.getMessage();
                if (message == null || message.isEmpty()) {
                    message = getString(R.string.signin_other_error);
                }


                new AlertDialog.Builder(this)
                        .setMessage(message)
                        .setNeutralButton(android.R.string.ok, null)
                        .show();
            }

        }
        super.onActivityResult(requestCode, resultCode, intent);
    }

编辑

现在,按照建议的方法操作后,登录对话框将立即关闭,而不会显示任何错误.

Now after following the suggested methods, the SignIn dialogue closes immediately without showing any errors.

推荐答案

ApiException的消息并没有真正告诉我们:

The message of the ApiException is not really telling:

String message = apiException.getMessage();

要调试此功能,ApiException的状态可能会有所帮助:

To debug this, the status of the ApiException would rather be helpful:

int StatusCode = apiException.getStatusCode();

请参见文档;它可能与oAuth2范围有关;但是问题是缺少构造GoogleSignInClient的代码(可能与重现错误有关).

See the documentation; It could have to do with oAuth2 scopes; but the question lacks the code where the GoogleSignInClient is being constructed (might be relevant to reproduce the error).

另一个怀疑可能是缺少或过时的 google-services.json .它需要添加用于签名APK程序包的密钥的匹配(调试或发行版,或二者兼有)密钥指纹.即使不使用Firebase,也必须在其中设置项目,以便添加密钥指纹并获得一个配置文件(字符串资源中必须有一些google_app_id,而这正是播放服务插件将从该配置文件中生成).

Another suspicion would be a missing or outdated google-services.json. It needs to have the matching (debug or release or both) key fingerprints added, of the keys used to sign that APK package. Even if not using Firebase, one has to setup the project there, in order to add the key fingerprints and to obtain that one config file (there has to be some google_app_id in the string resources and this is exactly what the Play Services Plugin would generate from that config file).

状态4表示

客户端尝试连接到服务,但用户未登录.

The client attempted to connect to the service but the user is not signed in.

客户端可以选择不使用API​​继续操作.

The client may choose to continue without using the API.

google_app_id的身份验证提示失败或密钥指纹不匹配.想想一个人不需要权限即可使用GoogleSignInClient来获取当前已登录的Google帐户...因此,这很可能意味着该API客户端未登录到Google Play.

A failed authentication hints for google_app_id or the key fingerprints not matching. Think one does not require permission to get the currently signed-in Google account with the GoogleSignInClient... so this likely means, the API client not being signed in to Google Play.

这篇关于如何在Android中正确设置Google Play登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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