gpt4 book ai didi

php - 如何在 php 中初始化 Cloud Firestore?

转载 作者:行者123 更新时间:2023-12-04 14:37:39 25 4
gpt4 key购买 nike

我按照这些教程在 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 - 如何在 php 中初始化 Cloud Firestore?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55769607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com