首页 > 解决方案 > Cloud Firestore API 未启用,尝试从 PHP 访问时出现 FAILED_PRECONDITION

问题描述

尝试从 PHP 访问 Cloud Firestore。我相信我已经正确设置了所有内容,并且它似乎正在接受我的授权文件,并且一直到快照行,但随后抛出错误“该项目未启用 Cloud Firestore API”。我有一个单独的 javascript 网页,可以毫无问题地访问该数据库;尝试为需要在 PHP 中的不同目的构建页面,并且无法克服此错误。任何帮助将非常感激...

putenv("GOOGLE_APPLICATION_CREDENTIALS=c:/XXX/google-auth.json");
require '/vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;
$db = new FirestoreClient();
$docRef = $db->collection('clients')->document('10001');
$snapshot = $docRef->snapshot();

完整的错误消息:致命错误:未捕获的 Google\Cloud\Core\Exception\FailedPreconditionException: { "message": "The Cloud Firestore API is not enabled for the project xxxxx", "code": 9, "status": "FAILED_PRECONDITION" , "详细信息": [] } 在 C:\vendor\google\cloud-core\src\GrpcRequestWrapper.php:263 堆栈跟踪:#0 C:\vendor\google\cloud-core\src\GrpcRequestWrapper.php(200 ): Google\Cloud\Core\GrpcRequestWrapper->convertToGoogleException(Object(Google\ApiCore\ApiException)) #1 [内部函数]: Google\Cloud\Core\GrpcRequestWrapper->handleStream(Object(Google\ApiCore\ServerStream)) # 2 C:\vendor\google\cloud-firestore\src\SnapshotTrait.php(122): Generator->current() #3 C:\vendor\google\cloud-firestore\src\SnapshotTrait.php(61): Google \Cloud\Firestore\DocumentReference->getSnapshot(Object(Google\Cloud\Firestore\Connection\Grpc), 'projects/cityda...', Array) #4 C:\vendor\google\cloud-firestore\src\DocumentReference.php(347): Google\ Cloud\Firestore\DocumentReference->createSnapshot(Object(Google\Cloud\Fires in C:\vendor\google\cloud-core\src\GrpcRequestWrapper.php 行 263

标签: phpgoogle-cloud-firestore

解决方案


推荐阅读