为什么我无法登录 google 玩游戏

Why I can't login on google play games

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

Logcat

I/salahtaha: com.google.android.gms.common.api.ApiException: 4: 4: 

清单

<?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>

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

}

我使用游戏服务在 google 游戏机上添加了游戏,它与 firebase 项目相关联。

Note : SHA1 in my app identical in my firebase

基于来自 Google API for Android

CommonStatusCodes

查看 API 异常,提供了状态代码 4,它与 Google 的 API 的 Android 文档中的以下信息相关联。

The client attempted to connect to the service but the user is not signed in. The client may choose to continue without using the API. Alternately, if hasResolution() returns true the client may call startResolutionForResult(Activity, int) to prompt the user to sign in. After the sign in activity returns with RESULT_OK further attempts should succeed.

另外,关于你调用SignInSliently的方法,我还查到了以下信息:

  • (void) signInSilently
    Attempts to sign in a previously authenticated user without interaction.
    The delegate will be called at the end of this process indicating success or failure.

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

归功于 noktigula for providing the source of these documentation in the APIException question 这导致了这个问题上的相同错误。