java - Google Play Games Android 登录出现错误代码 4
问题描述
我目前正在开发一个 Android 应用程序,我想在其中使用 Google Play 游戏服务(成就、排行榜等)。经过多次迭代,我终于得到了显示Google Play Games Login promt的代码。现在的问题是,用户登录后需要一段时间,然后抛出错误代码 4,错误消息为空。在做了很多研究之后,没有什么能真正帮助我解决这个问题。
我试过直接从 Android Studio 启动它,手动或通过 Google Play 安装应用程序,所有这些都在多个设备上,没有任何效果。
如果需要,这里有一些代码:
private static GoogleSignInClient mGoogleSignInClient;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).requestIdToken(getResources().getString(R.string.app_id)).build());
signInSilently(); // Can't be tested yet.
// isSignedIn() and loginDeclined are both false
if(!isSignedIn() && !loginDeclined) startSignInIntent();
}
...
private void startSignInIntent() {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
loginDeclined = true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
// resultCode = 0
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(intent);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
// Now this never happens :(
System.out.println("SUCCESS!");
} catch (ApiException apiException) {
System.out.println(apiException.getStatusCode() + " + " + apiException.getMessage());
// statusCode is 4, message is "4: "
String message = apiException.getMessage();
if (message == null || message.isEmpty()) {
message = "Error signing in to Google Play Games";
}
new android.app.AlertDialog.Builder(this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show();
}
}
}
解决方案
确保使用SHA1密钥。
命令“keytool -list -keystore [path to debug keystore] ”可能会显示一个SHA-256密钥。
要获取您的SHA1密钥,您可以按照以下步骤操作:
- 打开你的项目
- 点击“ Gradle ”(右侧)
- 选择您的模块
- 任务 -> android ->(双击)signingReport
推荐阅读
- c - 我不理解的 strtok() 行为
- jsf - JSF从没有显示的bean中设置inputText值
- kubernetes - Prometheus Alertmanager 是否能够区分事件和条件?
- java - 如何在android studio中从给定的mp3文件中获取音频数据
- android - Android Studio 中 Intentservice/coroutine/workmanager 中的后台数据更新
- r - 在ggplot中绘制多条线的功能
- akka - akka actor 可以在不同的情况下回复消息吗
- sql - 仅在最高组上的 Sql 查询 max/min
- flutter - 发现奇怪的错误:GetX+Provider 相处得不太好
- python-3.x - 如何将 pandas DataFrame 作为 CSV 文件传递到 Django View 的上下文中?