Firestore error : Stream closed with status : PERMISSION_DENIED

Viewed 11763

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;
    }
  }
}
9 Answers

Replace your rules with this and try:

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

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

This error can also occur if you haven't actually created the DB in your Firebase console.

I had the same problem, I solved it by removing the file:

app/build/generated/res/google-services/debug/values/values.xml

This file contained references to old google APIs and for some reason it wasn't being overwritten in the project build. When I manually removed the build process it was created again with the correct references.

If you use Android Studio just click on the top menu on Build and then on Clean Project and you get the same result.

try to enable the function from firebase. for my part, I forgot to enable cloud firestore when migrate to a new account. Try that !

Will opening the project for edit in android studio and letting it sync and making its indexing then giving it the permission to update the Gradle version did solve the problem for me, that happened because I added a new google-service.json file without doing that step.

Clearing the project cache solved the issue for me

Worked For Me:

  1. flutter clean
  2. flutter pub get

Clean the project and Synchronise with Gradle

Related