GoogleAuthProvider.getCredential 方法对我不起作用

GoogleAuthProvider.getCredential method does not work for me

我正在尝试关注 this tutorial

我创建了这个 firebaseAuthWithGoogle 函数:

 public void firebaseAuthWithGoogle(Activity context,FirebaseAuth mAuth, GoogleSignInAccount acct) {
    Log.i(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(context, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.i(TAG, "firebase signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.i(TAG, "firebase signInWithCredential" + task.getException());
                    }
                    // ...
                }
            });
}

我从这里打电话:

final GoogleSignInAccount acct = result.getSignInAccount();
        AsyncTask asyncTask = new AsyncTask() {
            @Override
            protected Object doInBackground(Object[] params) {
                try{
                    String scope =  "oauth2:" + Scopes.PROFILE;
                    Account account = new Account(acct.getEmail(), "com.google");
                    final String token  = GoogleAuthUtil.getToken(PSSignInFlowActivity.this, account, scope);                       PSSocialService.getInstance().firebaseAuthWithGoogle(PSSignInFlowActivity.this, PSApplicationClass.getInstance().mAuth, acct);
                }catch (Exception e){
                    Log.e("","firebase error trying to get client secret : " + e.getMessage());
                }
                return null;
            }
        };
        asyncTask.execute();

我的 idToken 是:firebaseAuthWithGoogle:1024xxxxxxxxxxxxxx956(所以它不是空的,添加它也许我也没有发送我所支持的东西?)

但是当我调试时,我得到这个错误: Must specify an idToken or an accessToken.

我做错了什么?他们在教程中使用相同的逻辑 PS:如果重要的话,我在 compile 'com.google.firebase:firebase-auth:10.2.0'

编辑:我注意到 acct.getIdToken() returns 为空,这是为什么呢? GoogleSignInAccount 不应该有 idToken 吗? 我正在注销 acct.getId(),这是我在上面写的 1024xxxxxxxxxxxxx956。

EDIT2:我在我的 GSO 中添加了这个选项:

 .requestIdToken(serverID)

现在我得到了 idToken,但我得到的回复是:

  04-05 10:34:16.388: I/PSSocialService(6285): firebase signInWithCredentialcom.google.firebase.FirebaseException: An internal error has occurred. [ Invalid Idp Response ]

服务器 ID 是:264xxxxxxxxxx27.apps.googleusercontent.com 这是我应该使用的正确值吗? 他们在教程中使用:

 .requestIdToken(getString(R.string.default_web_client_id))

但我试过了,它崩溃了,因为它说我需要使用相同的 clientID。 我将 serverID 用于 .requestServerAuthCode(serverID),我想这就是为什么

在 firebase 控制台中,Authentification/Providers/Google 需要添加所有外部客户端 ID,以便将它们列入白名单。这就是为什么它对我不起作用