我得到了错误

gettingdocuments.com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED:缺少或权限不足。

对于下面关于else语句的代码

db.collection("users")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
             if (task.isSuccessful()) {
                 for (DocumentSnapshot document : task.getResult()) {
                     s(document.getId() + " => " + document.getData());
                 }
             } else {
                 s("Error getting documents."+ task.getException());
             }
         }
     });

当前回答

对我来说,是日期的问题。更新后问题已解决。

允许读/写:

 if request.time < timestamp.date(2020, 5, 21);

编辑:如果您仍然感到困惑,无法找出问题所在,请查看firebase控制台的规则部分。

其他回答

此外,如果您的代码中的集合引用与firebase上的集合名称不匹配,则可能会出现此错误。

例如,firebase上的集合名称是users,但您使用db.collection(" users ")或db.collection("user")引用它。

它也是区分大小写的。

希望这对大家有所帮助

原始代码:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
          
    }
  }
}

修改代码:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
       allow read: if true;
       allow write: if request.auth != null;
    }
  }
}

我已经设法解决了我的问题。 我有2个错误:

PERMISSION_DENIED:缺少或权限不足。 不能为此项目启用Firestore。

修复此问题的步骤:

第1部分。

访问https://console.firebase.google.com/ Firestore Database ->删除所有集合 Firestore Database -> Rules ->删除所有规则历史记录

第2部分。

访问https://console.cloud.google.com/ 在菜单中找到:api和服务->已启用的api和服务 禁用3个服务:“云Firestore API”,“Firebase规则API”,“Firebase API的云存储” Firestore ->将自动启用“云Firestore API”和“Firebase规则API”服务,并将创建Firestore数据库。 启用“Firebase API的云存储”。

最重要的是从谷歌云控制台创建一个Firestore数据库。

确保你的数据库不是空的,你的查询是不存在的集合

对我来说,问题是AppCheck在我的Firestore控制台也被激活了。 所以我必须按照指南中所述的应用程序检查颤振指南

https://firebase.google.com/docs/app-check/flutter/debug-provider?hl=it&authuser=0

打开androidDebugProvider: true,从控制台复制调试令牌,并将其粘贴到Firestore部分(AppCheck—> app—> add调试令牌),它立即工作。