在 android 中尝试登录 Google 游戏服务时出现错误 403

Error 403 when trying to sign in to Google Game Services in android

我正在尝试使用 Google Android SDK 来唱歌,但出现了很多错误... 我看到了所有关于此错误和任何其他错误的 post,但仍然无法弄清楚。 我检查了 SH1,Google API,链接了我的应用程序,检查了 app_id。

这是我的代码:

            mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_PROFILE)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES)
                .build();

        @Override
        public void onStart() {
            super.onStart();
            mGoogleApiClient.connect();
        }

@Override
    public void onConnected(Bundle bundle) {
        System.out.println("Logged in");
    }

@Override
    public void onConnectionSuspended(int i) {
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        if (!mIntentInProgress && result.hasResolution()) {
            try {
                mIntentInProgress = true;
                startIntentSenderForResult(result.getResolution().getIntentSender(),
                        RC_SIGN_IN, null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                // The intent was canceled before it was sent.  Return to the default
                // state and attempt to connect to get an updated ConnectionResult.
                mIntentInProgress = false;
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onActivityResult(int requestCode, int responseCode, Intent intent) {
        super.onActivityResult(requestCode, requestCode, intent);
        if (requestCode == RC_SIGN_IN) {
            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public boolean isSignedIn() {
        return (mGoogleApiClient != null && mGoogleApiClient.isConnected());
    }

我得到的错误:

02-21 10:07:18.920 11247-11712/com.google.android.gms E/Volley﹕ [937] a.a: Unexpected response code 403 for https://www.googleapis.com/games/v1/players/me?language=en_US 02-21 10:07:18.980 11247-17039/com.google.android.gms E/SignInIntentService﹕ Access Not Configured. The API (Google Play Game Services API) is not enabled for your project. Please use the Google Developers Console to update your configuration. com.google.android.gms.games.h.c.a at com.google.android.gms.games.h.b.a(SourceFile:153) at com.google.android.gms.games.a.bj.d(SourceFile:1683) at com.google.android.gms.games.a.bj.b(SourceFile:610) at com.google.android.gms.games.a.bj.b(SourceFile:585) at com.google.android.gms.games.a.t.d(SourceFile:824) at com.google.android.gms.games.service.w.b(SourceFile:347) at com.google.android.gms.games.service.s.a(SourceFile:47) at com.google.android.gms.games.service.GamesSignInIntentService.onHandleIntent(SourceFile:499) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.os.HandlerThread.run(HandlerThread.java:61) 02-21 10:07:18.985 17012-17012/com.google.android.gms.ui E/LoadSelfFragment﹕ Unable to sign in - application does not have a registered client ID

我也陷入了 onActivityResultonConnectionFailed 之间的循环。我在 onConnectionFailed 中得到的错误代码是 4.

有人知道会是什么吗?

当您的应用程序未正确链接到您的项目时,会出现此错误。请检查您是否已为调试和发布证书链接 SHA1 指纹。

就我而言,当我使用 Google API 控制台(而不是 google play 开发者控制台)添加第二个 SHA1 指纹(发布版本)时出现此错误.

我建议在开发者控制台中删除您喜欢的应用,然后仅使用 google play 开发者控制台再次添加以管理 SHA1 密钥。按照此处的说明进行操作:

https://developers.google.com/games/services/console/enabling

我找到了解决方案: 我 link 使用错误的 SHA1 编辑了我的应用程序...我使用了一些自定义密钥或类似的东西。我尝试在我的设备上调试它,但没有成功。

解决方案是从位于此处的调试密钥中提取 SHA1 ->

C:\Users\.android\debug.keystore

然后 link 我的应用程序。