YouTube API代码突然返回一个错误



我们已经使用了几年的YouTube数据API来上传视频到我们的频道,但是截至昨天,我现在得到这个错误。

Call to undefined method GoogleServiceYouTubeVideo::getHeaderLine()

我们的上传代码已经几个月没有改变了,我们也有一段时间没有部署任何新版本的系统了,所以供应商的代码是不变的。

这是调用上传服务的代码(我没有写这个,但是我正在写一个新版本,所以这段代码可能已经过时了,它应该做什么)

$media = new Google_Http_MediaFileUpload($client, $request, $mimeType, null, true, $chunkSizeBytes);
$media->setFileSize(filesize($filePath));
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($filePath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
return $status;

这是从视频上传过程开始的那一刻开始的部分堆栈跟踪

Call to undefined method GoogleServiceYouTubeVideo::getHeaderLine()
{"file":"/var/www/release/20220602115951/vendor/google/apiclient/src/Http/MediaFileUpload.php","line":310,"code":0,"trace":[{"file":"/var/www/release/20220602115951/vendor/google/apiclient/src/Http/MediaFileUpload.php","line":289,"function":"fetchResumeUri","class":"Google\Http\MediaFileUpload"},
{"file":"/var/www/release/20220602115951/vendor/google/apiclient/src/Http/MediaFileUpload.php","line":126,"function":"getResumeUri","class":"Google\Http\MediaFileUpload"},
{"file":"/var/www/release/20220602115951/modules/you_tube/src/Services/YouTube.php","line":93,"function":"nextChunk","class":"Google\Http\MediaFileUpload"},
{"file":"/var/www/release/20220602115951/modules/you_tube/src/Services/YouTube.php","line":573,"function":"uploadVideoFile","class":"YouTube\Services\YouTube"}

如有任何帮助,不胜感激

这是在2.12.5中引入的一个问题

MediaFileUpload.php中的第309行有

$response = $this->client->execute($this->request, null); 

这一行应该是

$response = $this->client->execute($this->request, false); 

传递false而不是null是正确的行为,因为Http/REST.php中的第159行可以防止抛出错误

if (false === $expectedClass) {

似乎还没有发布补丁(截至2022年6月6日上午6:59 BST)

因此,手动更改MediaFileUpload.php中的第309行以将空值更改为false,将解决问题或将google api客户端恢复到2.12.4也将解决问题。

相关内容

最新更新