如何在Android中正确设置谷歌播放登录?

问题描述 投票:3回答:1

我用android开发了一款游戏。我尝试实施GooglePlay SignIn,但它显示错误。我无法调试此错误。我尝试在除模拟器之外的其他手机型号中安装应用程序。

码:

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

It Loads the GP Games

Then this happens

编辑

现在遵循建议的方法后,SignIn对话框立即关闭而不显示任何错误。

android google-play-services
1个回答
2
投票

ApiException的消息并没有真正说明:

String message = apiException.getMessage();

要调试这个,ApiException的状态会更有帮助:

int StatusCode = apiException.getStatusCode();

documentation;它可能与oAuth2范围有关;但问题是缺少构建GoogleSignInClient的代码(可能与重现错误有关)。

另一个怀疑是缺少或过时的google-services.json。它需要添加用于签署APK包的密钥的匹配(调试或释放或两者)关键指纹。即使不使用Firebase,也必须在那里设置项目,以便添加关键指纹并获取一个配置文件(字符串资源中必须有一些google_app_id,这正是Play Services Plugin将从中生成的配置文件)。


状态4意味着SIGN_IN_REQUIRED

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

客户可以选择继续而不使用API​​。

google_app_id的验证提示失败或关键指纹不匹配。认为一个人不需要获得使用GoogleSignInClient获取当前登录的Google帐户的权限......所以这可能意味着,API客户端未登录Google Play。

© www.soinside.com 2019 - 2024. All rights reserved.