我正在使用firebase存储来上载文件,但是当我上载时,我得到了这个错误

E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.android.gms.internal.zzand: Please sign in before trying to get a token.

我用谷歌搜索了一下,但找不到答案!
我已经在firebase登录了。

最佳答案

我想你在上传文件之前没有签名。在启动程序活动的oncreate()中,尝试以下代码

FirebaseAuth mAuth = FirebaseAuth.getInstance();

然后在onstart()中,
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
  // do your stuff
} else {
  signInAnonymously();
}

显著地()
private void signInAnonymously() {
    mAuth.signInAnonymously().addOnSuccessListener(this, new  OnSuccessListener<AuthResult>() {
            @Override
            public void onSuccess(AuthResult authResult) {
                // do your stuff
            }
        })
        .addOnFailureListener(this, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                Log.e(TAG, "signInAnonymously:FAILURE", exception);
            }
        });
}

这可以解决你的问题

07-24 09:47