Firestore 错误:流已关闭,状态为:PERMISSION_DENIED

Moh*_*min 5 kotlin firebase

我正在尝试对某些数据使用 firestore,但我在 firestore 控制台错误中看不到任何数据:

(c4326c7) Stream closed with status: Status{code=PERMISSION_DENIED, description=Cloud Firestore API has not been used in project 508621789005 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/firestore.googleapis.com/overview?project=508621789005 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., cause=null}.
Run Code Online (Sandbox Code Playgroud)

尽管我允许读取,但写入规则为 true。

val db = FirebaseFirestore.getInstance()
    // Create a new user with a first and last name
            val user: MutableMap<String, Any> = HashMap()
            user["first"] = "Ada"
            user["last"] = "Lovelace"
            user["born"] = 1815

    // Add a new document with a generated ID
            db.collection("users")
                .add(user)
                .addOnSuccessListener { documentReference ->
                    Log.d(
                        TAG,
                        "DocumentSnapshot added with ID: " + documentReference.id
                    )
                }
                .addOnFailureListener { e -> Log.w(TAG, "Error adding document", e) }
Run Code Online (Sandbox Code Playgroud)

规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
       allow read, write: if true;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Meh*_*anB 10

以此替换您的规则并尝试:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{multiSegment=**} {
      allow read, write;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


Moh*_*min 3

我通过创建一个新项目解决了这个问题。因为项目id似乎有问题。