当我在youtube中上传视频时,我尝试使用不同的方法来设置缩略图,但是我没有获得任何成功,所以我现在被困住了。
$videoPath = 'videos/dlrcodexow-file_example_MP4_480_1_5MG.mp4';
$snippet = new Google_Service_YouTube_VideoSnippet();
$thumbnailDetails = new Google_Service_YouTube_ThumbnailDetails();
$thumbnail = new Google_Service_YouTube_Thumbnail();
$thumbnail->setHeight(110);
$thumbnail->setUrl('videos/test.png');
$thumbnail->setWidth(90);
$thumbnailDetails->setDefault($thumbnail);
$snippet->setThumbnails($thumbnailDetails);
$snippet->setTitle('hello');
$snippet->setDescription('test video');
$snippet->setTags(explode(",", 'test,test'));
$snippet->setCategoryId("22");
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = 'public';
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$insertRequest = $youtube->videos->insert("status,snippet", $video);
$media = new Google_Http_MediaFileUpload($client,$insertRequest,'video/*',null,true,$chunkSizeBytes);
$media->setFileSize(filesize($videoPath));
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
$client->setDefer(false);
$videoTitle = $status['snippet']['title'];
$videoDesc = $status['snippet']['description'];
$videoTags = implode(",",$status['snippet']['tags']);
$videoId = $status['id'];
视频已正确上传到youtube频道,但未在缩略图中设置图片。