我用android开发了一个游戏。我尝试实现GooglePlay登录,但显示错误。我无法调试此错误。我尝试在模拟器以外的其他手机型号上安装该应用程序。
代码:
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);
}
编辑
现在,按照建议的方法操作后,登录对话框将立即关闭,而不会显示任何错误。
答案 0 :(得分:2)
ApiException
的消息并没有真正告诉我们:
String message = apiException.getMessage();
要调试此功能,ApiException
的状态可能会有所帮助:
int StatusCode = apiException.getStatusCode();
请参见documentation;它可能与oAuth2范围有关;但问题是缺少构建GoogleSignInClient
的代码(可能与重现错误有关)。
另一个怀疑可能是缺少或过时的google-services.json。它需要添加用于签名APK
软件包的密钥的匹配(调试或发行或二者兼有)密钥指纹。即使不使用Firebase,也必须在那里安装项目,以便添加密钥指纹并获得一个配置文件(字符串资源中必须有一些google_app_id
,而这正是{ {3}}将从该配置文件生成。
状态4
表示Play Services Plugin:
客户端尝试连接到服务,但用户未登录。
客户端可以选择不使用API继续操作。
google_app_id
的身份验证提示失败或密钥指纹不匹配。想想一个人不需要权限即可使用GoogleSignInClient
来获取当前已登录的Google帐户...因此,这很可能意味着该API客户端未登录到Google Play。