Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore error : Stream closed with status : PERMISSION_DENIED

I am trying to use firestore to certain data,but i can't see any data in firestore console error:

(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}.

Although i allowed read,write in rules to 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) }

Rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
       allow read, write: if true;
    }
  }
}
like image 723
Mohamed Amin Avatar asked Mar 01 '23 20:03

Mohamed Amin


2 Answers

Replace your rules with this and try:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{multiSegment=**} {
      allow read, write;
    }
  }
}
like image 62
MehranB Avatar answered Mar 05 '23 16:03

MehranB


I solved the problem by creating a new project.Becuase it seems that there was a problem in project id.

like image 30
Mohamed Amin Avatar answered Mar 05 '23 17:03

Mohamed Amin