为什么我无法登录 google play games

Tah*_*ami 1 android android-studio google-play-games

我 1 天前尝试登录 Google Play 游戏,但从来没有登录过,除非我收到以下消息。

日志猫

I/salahtaha: com.google.android.gms.common.api.ApiException: 4: 4: 
Run Code Online (Sandbox Code Playgroud)

显现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.salah250.test.test">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

Java代码

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    private void signInSilently() {
        GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
                GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
        signInClient.silentSignIn().addOnCompleteListener(this,
                new OnCompleteListener<GoogleSignInAccount>() {
                    @Override
                    public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                        if (task.isSuccessful()) {
                            GoogleSignInAccount signedInAccount = task.getResult();
                            Toast.makeText(MainActivity.this, "a", Toast.LENGTH_SHORT).show();
                        } else {
                            Log.i("salahtaha",String.valueOf(task.getException()));
                        }
                    }
                });
    }

    @Override
    protected void onResume() {
        super.onResume();
        signInSilently();
    }

}
Run Code Online (Sandbox Code Playgroud)

我使用游戏服务在 google play console 上添加了游戏,并且它与 firebase 项目链接。

注意:我的应用程序中的 SHA1 与我的 firebase 中的相同

Ner*_*ero 5

基于Google API for AndroidCommonStatusCodes

查看 API 异常,提供状态代码 4,该状态代码与 Google Android API 文档中的以下信息链接。

客户端尝试连接到服务,但用户未登录。客户端可以选择继续而不使用 API。或者,如果 hasResolution() 返回 true,则客户端可以调用 startResolutionForResult(Activity, int) 来提示用户登录。登录活动返回 RESULT_OK 后,进一步的尝试应该会成功。

另外,您调用 SignInSliently 的方法,我还发现了以下信息:

  • (void) signInSilently
    尝试在不进行交互的情况下登录之前经过身份验证的用户。
    在此过程结束时将调用委托来指示成功或失败。

因此,我认为您尝试登录时没有任何经过身份验证的登录记录。为了使用 SignInSilently,您必须手动登录该服务。

感谢noktigula在APIException 问题中提供了这些文档的来源,这导致了该问题上的相同错误。