1
votes

I'm following official firestore quick start tutorial here is my code -

use Google\Cloud\Firestore\FirestoreClient;
require 'vendor/autoload.php';
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);


initialize();



function initialize()
{
    // Create the Cloud Firestore client
    $db = new FirestoreClient();
    printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
    $docRef = $db->collection('users')->document('lovelace');
    $docRef->set([
        'first' => 'Ada',
        'last' => 'Lovelace',
        'born' => 1815
    ]);
    printf('Added data to the lovelace document in the users collection.' . PHP_EOL);

}

I'm getting this error message Uncaught Google\Cloud\Core\Exception\ServiceException: { "message": "Request had insufficient authentication scopes.", "code": 7, "status": "PERMISSION_DENIED",

My database rules are

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}
1

1 Answers

0
votes

You should adapt your rules as follows:

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

Note however, that with these rules you "allow read/write access to all users under any conditions". It is highly recommended to change them when going to production, see https://firebase.google.com/docs/firestore/security/get-started