You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

导入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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 03:20:15