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

使用google-api-php-client时遇Class 'Google\Client'未找到错误求助

版本信息
  • Composer:2.4.0
  • PHP:7.4.30
  • Apache:2.4.29
  • google-api-php-client:未知
基本信息

使用google-api-php-client创建客户端对象时触发错误:

Fatal error: Uncaught Error: Class 'Google\Client' not found

按官方文档操作到基础示例步骤时卡住,运行示例代码验证配置出现上述错误。使用Composer加载依赖,代码如下:

require_once $coreRoot . 'objects/googleOAuth2/vendor/autoload.php';
$client = new Google\Client();    
$client->setAuthConfig(/* 安全密钥JSON文件 */);

$coreRoot变量为当前PHP文件所在目录的完整路径。

已尝试的方案

查阅多个Stack Overflow问题均未解决:

  • Class 'Google_Client' not found
  • Fatal error: Uncaught Error: Class 'Google_Client' not found
  • Fatal error: Uncaught Error: Class 'Google_client' not found despite adding library through composer
  • Laravel: Class 'Google_Client' not found
其他信息

Composer生成的composer.json文件:

{
    "require": {
        "google/apiclient": "2.12.1"
    }
}

原始composer.json文件:

{
    "name": "google/apiclient",
    "type": "library",
    "description": "Client library for Google APIs",
    "keywords": ["google"],
    "homepage": "http://developers.google.com/api-client-library/php",
    "license": "Apache-2.0",
    "require": {
        "php": "^5.6|^7.0|^8.0",
        "google/auth": "^1.10",
        "google/apiclient-services": "~0.200",
        "firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0||~6.0",
        "monolog/monolog": "^1.17||^2.0||^3.0",
        "phpseclib/phpseclib": "~2.0||^3.0.2",
        "guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0",
        "guzzlehttp/psr7": "^1.8.4||^2.2.1"
    },
    "require-dev": {
        "squizlabs/php_codesniffer": "^3.0",
        "symfony/dom-crawler": "~2.1",
        "symfony/css-selector": "~2.1",
        "cache/filesystem-adapter": "^0.3.2|^1.1",
        "phpcompatibility/php-compatibility": "^9.2",
        "composer/composer": "^1.10.22",
        "yoast/phpunit-polyfills": "^1.0",
        "phpspec/prophecy-phpunit": "^1.1||^2.0",
        "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
    },
    "suggest": {
        "cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)"
    },
    "autoload": {
        "psr-4": {
            "Google\\": "src/"
        },
        "files": [
            "src/aliases.php"
        ],
        "classmap": [
            "src/aliases.php"
        ]
    },
    "extra": {
        "branch-alias": {
            "dev-main": "2.x-dev"
        }
    }
}
备注

若遗漏细节或内容有不清楚的地方,请评论指出,我会补充修正。

内容的提问来源于stack exchange,提问作者Jonathan J. Pecany

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 01:15:39