发生内部错误。 [access_token无效,错误代码43.]

时间:2016-08-23 10:02:55

标签: android firebase firebase-authentication facebook-authentication

当我使用Firebase的Facebook凭据静默登录我的APP时,会返回此错误消息。

An internal error has occured. [ invalid access_token, error code 43. ]

我在首次登录时将Facebook令牌保存在SharedPreferences中,并在两次登录时获取它,然后使用FacebookAuthProvider.getCredential(accessToken);创建凭据。最后,我使用以下代码登录此凭证:

private void signInFirebase(AuthCredential credential, final TaskCompleteListener signInListener) {
    FirebaseAuth.getInstance().signInWithCredential(credential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Logger.i(TAG,"Firebase login success.");
                    } else {
                        Logger.e(TAG,"Firebase login failure:"+task.getException().getMessage());
                    }
                }
            });
}

它总是打印出标题。 我尝试了什么,而不是工作:

1.change Firebase version from 9.0.2 to 9.4.0
2.search error message in Google directly

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Firebase在应用重启之间已经持续存在用户的登录状态。因此,不要自己持久保存Facebook令牌,monitor whether the user is already authenticated with Firebase

从该文件:

FirebaseAuth.getInstance(). addAuthStateListener(new FirebaseAuth.AuthStateListener() {
    @Override
    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
        FirebaseUser user = firebaseAuth.getCurrentUser();
        if (user != null) {
            // User is signed in
            Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
        } else {
            // User is signed out
            Log.d(TAG, "onAuthStateChanged:signed_out");
        }
        // ...
    }
});