【问题标题】:After uploading/importing video files to Youtube - getting [Raw file: unknown]将视频文件上传/导入到 Youtube 后 - 获取 [原始文件:未知]
【发布时间】: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”可以和文件同名吗?

【问题讨论】:

标签: php youtube youtube-api


【解决方案1】:

如果您想在 API 上传中包含文件名,您必须将 fileDetails 部分添加到您的 API 上传请求中,并将 fileDetails 对象包含在您的请求正文中,并将 fileName 参数设置为文件名你想要的。

这在此处记录:https://developers.google.com/youtube/v3/docs/videos#fileDetails.fileName

【讨论】:

    猜你喜欢
    • 2016-02-05
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多