【问题标题】:Android firebase throws authentication error while trying to access storageAndroid firebase 在尝试访问存储时引发身份验证错误
【发布时间】:2020-09-27 11:59:20
【问题描述】:

编辑:清理项目并使缓存无效后,我刚刚重新启动了 Android Studio。现在我得到这个错误 -

E/StorageException: {  "error": {    "code": 403,    "message": 
"Permission denied. Could not perform this operation"  }}

我收到以下无限打印的错误。

2020-09-27 17:00:32.931 11755-11863/com.example.XXXXXX E/StorageUtil:获取令牌时出错 java.util.concurrent.ExecutionException:com.google.firebase.internal.api.FirebaseNoSignedInUserException:请在尝试获取令牌之前先登录。

在我的应用程序中,我已正确创建用户,FirebaseAuth.getInstance().getCurrentUser(); 不会返回 null。但如果是这样,我会通过成功登录或创建另一个用户来处理它。我的应用现在在不到半天的时间内就创建了 160 多个用户。我认为我什至没有多次运行该应用程序进行测试。 “使用电子邮件登录”和“匿名登录”选项已在身份验证设置中启用。

当我尝试访问存储时,问题就开始了。我收到上述身份验证令牌错误。文件夹和文件存在,这就是我尝试下载文件的方式 -

            fstore.child("gs://XXXXXX-XXXX.appspot.com/Books/XXXX").listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
            @Override
            public void onSuccess(ListResult listResult) {
                for(StorageReference sref : listResult.getItems())
                {
                    tempFilename = sref.getName();
                    File tmpFile = new File(tempSubDir, tempFilename);
                    try {
                        tmpFile.createNewFile();
                        sref.getFile(tmpFile).addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                Toast.makeText(tabtwoactivity.this, "File download failed!", Toast.LENGTH_LONG).show();
                                System.out.println("ERROR: "+ e.toString());
                            }
                        });
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    //System.out.println("IIIIII: "+sref.getName());
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(tabtwoactivity.this, "Fetching Directory XXXXX Failed", Toast.LENGTH_LONG).show();
            }
        });

我尝试过使用fstore.child("XXXX").listAll(),但这给了我大量不同的错误,主要集中在Folder not found。我的存储有文件夹和文件。我什至玩过存储规则-allow read, write;allow read, write: if request.auth!=nullallow read, write: if request.auth==null。但没有任何效果。

我做错了什么?

【问题讨论】:

  • 你用谷歌账号登录过android studio吗?
  • @Jandroid 是的,我有。但这真的是一个足够大的考虑因素吗?
  • 因为我没有登录android studio的时候,报错了。
  • 但这并不是什么大不了的事情。
  • android studio 似乎无法访问您的数据库。

标签: java android firebase firebase-storage


【解决方案1】:

将此粘贴​​到您的 google.json 中:

service firebase.storage {
  // The {bucket} wildcard indicates we match files in all storage buckets
  match /b/{bucket}/o {
    // Match filename
    match /filename {
      allow read: if true;
      allow write: if true;
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 2017-03-16
    • 2022-01-03
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多