我得到了错误

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());
             }
         }
     });

当前回答

转到Apple Certificates, Identifiers & Profiles: 选择您的密钥上传firebase并进行检查: 访问DeviceCheck和apptest api以获取您关联的数据

在这里输入图像描述

其他回答

进入数据库-> 规则- - - >

发展:

更改允许读,写:如果为false;真正的;

注意:它只是用于开发目的的快速解决方案,因为它将关闭所有安全性。因此,不建议在生产中使用。

生产:

如果从firebase验证:更改允许读,写:如果为false;请求。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数据库。

这里的变化 将false设为true

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

并发布新的规则

经过批准的答案是非常危险的,因为任何人都可以在没有任何许可的情况下读取或写入您的数据库。我建议用这个。

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

这将允许授权人员写入数据库,而任何人都可以读取数据库,以防访问者访问网站。