导入Firestore遇报错:Class 'Google\ApiCore\Serializer'未找到
Firestore导入时出现类找不到的致命错误
错误详情
Fatal error: Uncaught Error: Class "Google\ApiCore\Serializer" not found in /public_html/sendimgs/vendor/google/cloud-core/src/GrpcRequestWrapper.php:93 Stack trace: #0 /public_html/sendimgs/vendor/google/cloud-firestore/Connection/Grpc.php(81): Google\Cloud\Core\GrpcRequestWrapper->__construct(Array) #1 /public_html/sendimgs/vendor/google/cloud-firestore/FirestoreClient.php(111): Google\Cloud\Firestore\Connection\Grpc->__construct(Array) #2 /public_html/sendimgs/Firestore.php(14): Google\Cloud\Firestore\FirestoreClient->__construct(Array) #3 /public_html/sendimgs/index.php(19): Firestore->__construct() #4 {main} thrown in /sendimgs/vendor/google/cloud-core/src/GrpcRequestWrapper.php on line 93
自定义Firestore.php代码
<?php use Google\Cloud\Firestore\FirestoreClient; use Google\Cloud\Firestore\DocumentReference; use Google\Cloud\Firestore\CollectionReference; class Firestore { private FirestoreClient $firestore; public function __construct() { $this->firestore = new FirestoreClient([ ... ]); } public function getData() { return $this->firestore->...; } }
解决方法
- 重新安装依赖:执行
composer install或composer update,确保google/api-core等所有Google Cloud相关依赖完整安装。 - 确认自动加载文件引入:检查入口文件(比如index.php)是否正确引入了
vendor/autoload.php,没有的话添加代码require_once __DIR__ . '/vendor/autoload.php';。 - 排查版本兼容性:查看
composer.json中google/cloud-firestore与google/api-core的版本是否匹配,避免版本冲突导致依赖缺失。
内容的提问来源于stack exchange,提问作者Xacoio
相关产品推荐
相关产品推荐

