<?php
$videoPath = "http://test.com/Uploads/UserProfile/test.mp4";
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test description");
$snippet->setTags(array("tag1", "tag2"));
$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;
$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, "r");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
此代码返回错误,如
警告:第114行的D:\ Xampp \ htdocs \ Youtube_Demo \ test.php中的http://test.com/Uploads/UserProfile/test.mp4的filesize():stat失败
发生服务错误:调用PUT时出错 https://www.googleapis.com/upload/youtube/v3/videos? // herepart = status%2Csnippet&amp; uploadType = resumable&amp; upload_id = AEnB2UpagkMMJT7D1QCKY // l0GqdzlQFOMm6esWmtbuL0qjsbx4Sj1lekLD-LigsawnHVIKDlfugtl5nukaJ-PzbXAEBO7lx794A://(400)无法解析Content-Range标题。