Google登录失败(ApiException:12501)

时间:2018-05-01 11:53:20

标签: firebase android-studio google-play-services google-signin google-play-games

我尝试使用Google Play游戏登录。这是代码:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
            .requestServerAuthCode(getString(R.string.default_web_client_id))
            .build();

googleSignInClient = GoogleSignIn.getClient(this, gso);

我使用以下代码启动GoogleSignInActivity:

        @Override
        public void onClick(View view) {
            Intent intent = googleSignInClient.getSignInIntent();
            startActivityForResult(intent, SIGN_IN_CODE);
        }
    });

然后,它返回到这里:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == SIGN_IN_CODE){
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
            updateUI(null);
        }
    }
}

所以在这一行:

Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

我收到此错误:

Google sign in failed: com.google.android.gms.common.api.ApiException: 12501

SHA1证书没有任何错误,因为我已多次生成并将其粘贴到Firebase控制台中,我也在清单文件中拥有此权限:

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

我的代码中的任何一部分都已弃用。我正在使用最新的依赖项:

implementation 'com.google.firebase:firebase-auth:15.0.0'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'

我已阅读所有可能的文档。我对此非常绝望,差不多一周就出现了这个问题......

1 个答案:

答案 0 :(得分:0)

更改

GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN

GoogleSignInOptions.DEFAULT_SIGN_IN