首页 > 解决方案 > 尝试加载 YouTube PHP API 时找不到类

问题描述

我一直在尝试加载 YouTube API(通过 Google Client v2.5),但我一直遇到错误:

"error_message": "Class 'Google_Service_YouTube_Resource_Activities' not found",
"location": "[path snip]\/external\/google\/apiclient-services\/src\/Google\/Service\/YouTube.php:100"

作为测试,我尝试在GitHub 页面上运行基本示例,并且正确加载了 Books API。(请求失败,因为 Books 范围未注册到我的 API 密钥,但它确实正确加载并尝试调用。)因此,自动加载似乎正在工作,除了 YouTube API 每次都卡在这里。

尝试加载 API 的代码位于命名空间内的类的构造函数中:

    $this->gclient = new \Google_Client();
    $this->gclient->setApplicationName($settings['appname']);
    $this->gclient->setDeveloperKey($settings['apikey']);
    $this->gclient->addScope(\Google_Service_YouTube::YOUTUBE_READONLY);

    $this->yclient = new \Google_Service_YouTube($this->gclient);

这些库是通过 PHP Composer 安装的,并且vendor路径被修改为external使用它的选项。服务器正在运行 PHP 7.3.19。

标签: phpgoogle-api-php-client

解决方案


原来,问题出在文件权限上。它现在可以运行,在运行chmod修复后。


推荐阅读