如何在 php 中初始化 Cloud Firestore?
How do I initialize Cloud Firestore in php?
我按照这些教程在 PHP 中使用 Firestore:
https://github.com/googleapis/google-cloud-php-firestore https://firebase.google.com/docs/firestore/quickstart
但是当我加载页面时,会显示此消息:
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'
这是我的代码:
composer.json :
{
"require": {
"google/cloud-firestore": "^1.4",
"grpc/grpc": "v1.19.0"
}
}
index.php(示例副本):
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
]);
您似乎没有设置默认项目 ID。
尝试将 GCLOUD_PROJECT
环境变量设置为您的项目 ID。
set GCLOUD_PROJECT=PROJECT_ID
您也可以尝试像这样设置项目 ID:
$db = new FirestoreClient([
'projectId' => 'my-project-id',
]);
我按照这些教程在 PHP 中使用 Firestore: https://github.com/googleapis/google-cloud-php-firestore https://firebase.google.com/docs/firestore/quickstart
但是当我加载页面时,会显示此消息:
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'
这是我的代码:
composer.json :
{
"require": {
"google/cloud-firestore": "^1.4",
"grpc/grpc": "v1.19.0"
}
}
index.php(示例副本):
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
]);
您似乎没有设置默认项目 ID。
尝试将 GCLOUD_PROJECT
环境变量设置为您的项目 ID。
set GCLOUD_PROJECT=PROJECT_ID
您也可以尝试像这样设置项目 ID:
$db = new FirestoreClient([
'projectId' => 'my-project-id',
]);