我希望CMS的用户能够将视频上传到YouTube。我已经在PHP中开发了上传功能,但无法通过API设置缩略图。我收到此错误:
Google_Service_Exception: { "error": { "errors": [ { "domain": "youtube.thumbnail", "reason": "forbidden", "message": "The thumbnail cant be set for the specified video. The request might not be properly authorized.", "locationType": "parameter", "location": "videoId" } ], "code": 403, "message": "The thumbnail cant be set for the specified video. The request might not be properly authorized." } } in /data/site/comun/clases/google-api/src/Google/Http/REST.php on line 118
Call Stack
# Time Memory Function Location
1 0.0011 405168 {main}( )
2 0.0898 1355296 Google_Http_MediaFileUpload->nextChunk( )
3 0.3214 1974048 Google_Http_MediaFileUpload->makePutRequest( ) .../MediaFileUpload.php:140
4 0.3214 1974048 Google_Client->execute( ) .../MediaFileUpload.php:163
5 0.3232 1970872 Google_Http_REST::execute( ) .../Client.php:798
6 0.3232 1971816 Google_Task_Runner->run( ) .../REST.php:58
这是相关的代码。我已经完成了与API的正确连接,已经拥有所有相关权限,我们是YouTube的合作伙伴,我们的帐户是多渠道帐户,可以在YouTube CMS中手动上传图片。
$videoId = "whatever";
$imagePath = "/somewhere/over/the/rainbow.jpg";
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$request = $service->thumbnails->set($videoId);
$media = new Google_Http_MediaFileUpload($client, $request, 'image/jpeg', null, true, $chunkSizeBytes);
$media->setFileSize(filesize($imagePath));
$status = false;
$handle = fopen($imagePath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
我在“ $ status = $ media-> nextChunk($ chunk);”行得到错误。当它尝试上传第一个块时。有什么想法吗?