【发布时间】:2015-07-25 12:49:55
【问题描述】:
我设法通过此示例代码上传视频
$videoPath = "/path/to/file.mp4";
// Create a snippet with title, description, tags and category ID
// Create an asset resource and set its snippet metadata and type.
// This example sets the video's title, description, keyword tags, and
// video category.
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test description");
$snippet->setTags(array("tag1", "tag2"));
// Numeric video category. See
// https://developers.google.com/youtube/v3/docs/videoCategories/list
$snippet->setCategoryId("22");
// Set the video's status to "public". Valid statuses are "public",
// "private" and "unlisted".
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";
// Associate the snippet and status objects with a new video resource.
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
// Specify the size of each chunk of data, in bytes. Set a higher value for
// reliable connection as fewer chunks lead to faster uploads. Set a lower
// value for better recovery on less reliable connections.
$chunkSizeBytes = 1 * 1024 * 1024;
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$client->setDefer(true);
// Create a request for the API's videos.insert method to create and upload the video.
$insertRequest = $youtube->videos->insert("status,snippet", $video);
// Create a MediaFileUpload object for resumable uploads.
$media = new Google_Http_MediaFileUpload(
$client,
$insertRequest,
'video/*',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($videoPath));
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);
来自https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads
上传文件后,我在“Video Information”列中收到[Raw file: unknown]
在此页面https://www.youtube.com/upload 上通过“Import your videos from Google+”将文件从 Google Drive 上传到 YouTube 也会发生同样的情况。
当我在上传的视频上单击“Edit”按钮时,我们会转到此网址https://www.youtube.com/edit?o=U&video_id=XXX,在“Video Information”列中有“Raw file: unknown”。
所有上传的视频文件都有正常的标题,它们是video/mp4 mime 类型。
我在 Google Drive API 上没有找到任何关于如何更改它的信息。
代替“unknown”可以和文件同名吗?
【问题讨论】:
-
我看到问题跟踪器中填写了一个问题:code.google.com/p/gdata-issues/issues/…。为该问题投票。
标签: php youtube youtube-api