在尝试加载YouTube PHP API时没有找到类。

问题描述 投票:0回答:1

我一直在尝试加载YouTube API(通过谷歌客户端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页面,并且图书API正确加载。(请求失败是因为Books scope没有注册到我的API key上,但它确实正确加载并尝试调用。) 所以,自动加载似乎是有效的,只是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。

php google-api-php-client
1个回答
0
投票

我不确定gclient和yClient是什么。

首先,你似乎忘了添加你的客户端秘密json文件。 我不知道你要使用哪种方法,但是大多数的youtube api都需要认证。 你只有一个api密钥,只能在公共方法上使用。

$client = new Google_Client();
$client->setAccessType("offline");        // offline access.  Will result in a refresh token
$client->setIncludeGrantedScopes(true);  
$client->setAuthConfig(__DIR__ . '/client_secrets.json');
$client->addScope([YOUR SCOPES HERE]);
$client->setRedirectUri(getRedirectUri());  

$service = new Google_Service_Youtube($client); 

0
投票

原来,问题出在文件权限上。现在可以了,在运行 chmod 来解决这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.