0

我正在尝试让用户登录 Google Play 游戏服务,以跟踪他们的分数和成就,并开始使用排行榜。

我得到的错误是 Status{statusCode=SIGN_IN_REQUIRED, resolution=null},状态码为 4。我已经检查了 SHA1、包名称等三倍,但无法弄清楚出了什么问题。Play 游戏 UI 会闪烁几秒钟,显示“正在连接到 Play 游戏”。

我已经完成了以下工作:

• 在控制台中设置的凭据包括范围“./auth/games”(无敏感范围)。

• 测试人员在控制台上添加了我的 gmail 地址。

• 使用应用程序 ID 更新清单,如控制台上的“配置”页面所示:

    <meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>

• 我使用了以下依赖项:

implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.android.gms:play-services-games:21.0.0'
implementation 'com.google.firebase:firebase-auth:20.0.4'

• 使用以下代码登录:

private void startSignInIntent() {
    GoogleSignInClient signInClient = GoogleSignIn.getClient(MainActivity.this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // The signed in account is stored in the result.
            GoogleSignInAccount signedInAccount = result.getSignInAccount();
        } else {
            String message = result.getStatus().getStatusMessage();
            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();
        }
    }
}
4

0 回答 0