Google Play登录不断失败异常:4 [英] Google Play Sign in keeps failing Exception: 4

查看:187
本文介绍了Google Play登录不断失败异常:4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在尝试很长一段时间,以使我的应用获得Google玩游戏的成就,但我无法使其正常运行.我一直在遵循此指南: https://developers.google. com/games/services/android/signin#implementing_player_sign-in 并没有成功,每次我打开我的应用程序时,它都会启动登录过程,但随后会停止并显示失败.这可能是我想念的,但是我仍然无法弄清楚.

So I've been trying for a long time now to get my app the have google play games achievements and I can't get it to work. I've been following this guide: https://developers.google.com/games/services/android/signin#implementing_player_sign-in and am having no success, every time I open my app it starts the sign in process but then it stops and says it's failed. It's probably something I missed, but I still can't figure it out.

输入一些代码的时间:

build.gradle:

build.gradle:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation "com.google.android.gms:play-services-games:12.0.1"
    implementation "com.google.android.gms:play-services:12.0.1"
    implementation 'com.android.support:multidex:1.0.3'
}

清单:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.one.second">
<uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:label="One Second"
    android:icon="@drawable/app_icon"
    android:theme="@style/AppTheme">
    <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"/>
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|screenSize"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category   android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity
        android:name=".LowestActivity"
        android:configChanges="orientation|screenSize"
        android:screenOrientation="portrait"/>
</application>

main.java中重要的部分:

The parts of main.java that are important:

private static final int RC_SIGN_IN = 9001;

@Override
protected void onCreate(Bundle _savedInstanceState) {
    ...
    signInSilently();
}

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()) {
                        Log.d(TAG, "Success signInSilently");
                        GoogleSignInAccount signedInAccount = task.getResult();
                    } else {
                        Log.d(TAG, "Failed signInSilently");
                        startSignInIntent();
                    }
                }
            });
}

private void startSignInIntent() {
    Log.d(TAG, "startSignInIntent()");
    GoogleSignInClient signInClient = GoogleSignIn.getClient(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) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        Log.w(TAG, "signInResult:success");
    } catch (ApiException e) {
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
        signInSilently();
    }
}

ids.xml

...
<!-- app_id -->
<string name="app_id" translatable="false">874********</string>
...

查看图片:

推荐答案

根据我的经验,此错误可能是由3种不同的原因引起的:

In my experience this error can be caused by 3 different reasons:

  1. 您需要先手动登录,然后才能使用silentSignIn.

  1. You need to login manually before you can use silentSignIn.

您尚未将要测试的电子邮件添加到Google Play游戏控制台的测试人员"标签中(或启用了所有电子邮件).

You haven't added the emails you are testing with to the Testers tab in Google Play Games Console (or enable all emails).

您的构建没有使用与您生成Google Play游戏应用ID相同的SHA1密钥进行签名

Your build hasn't been signed with the same SHA1 key that your Google Play Games app id was generated with

裁判:

在Android上使用GoogleSignInClient进行静默签名的ApiException

Google Play游戏服务错误代码400

这篇关于Google Play登录不断失败异常:4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆