我一直在尝试加载Google (通过YouTube 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"
作为测试,我尝试在the GitHub page上运行基本示例,并且Books API正确加载。(请求失败,因为Books作用域没有注册到我的API密钥,但它确实正确加载并尝试调用。)因此,自动加载似乎可以正常工作,只是YouTube应用程序接口每次都会在这里卡住。
尝试加载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。
发布于 2020-06-18 19:33:08
原来,问题出在文件权限上。在运行chmod
修复之后,它现在可以工作了。
发布于 2020-06-16 10:42:44
我不确定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);
https://stackoverflow.com/questions/62397446
复制