Reputation: 153
I followed these tutorials to use Firestore in PHP : https://github.com/googleapis/google-cloud-php-firestore https://firebase.google.com/docs/firestore/quickstart
but when I load my page, this message is displayed :
Google\ApiCore\ValidationException: Error rendering 'projects/{project=}/databases/{database=}': expected binding 'project' to match segment '{project=*}', instead got null Provided bindings: Array ( [project] => [database] => (default) ) in C:\wamp64\www\php\vendor\google\gax\src\ResourceTemplate\RelativeResourceTemplate.php on line 238'
This is my code :
composer.json :
{
"require": {
"google/cloud-firestore": "^1.4",
"grpc/grpc": "v1.19.0"
}
}
index.php (copy of exemple):
require ('vendor/autoload.php');
use Google\Cloud\Firestore\FirestoreClient;
/**
* Initialize Cloud Firestore with default project ID.
* ```
* 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
]);
Upvotes: 4
Views: 7001
Reputation: 6854
Looks like you don't have a default project ID set.
Try setting the GCLOUD_PROJECT
environment variable to your project ID.
set GCLOUD_PROJECT=PROJECT_ID
You can also try setting the project ID like this:
$db = new FirestoreClient([
'projectId' => 'my-project-id',
]);
Upvotes: 12