php - 将视频文件上传/导入到 Youtube 后 - 获取 [原始文件 : unknown]

标签 php youtube youtube-api

我通过这个示例代码成功上传了视频

$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 上的“从 Google+ 导入您的视频”将文件从 Google Drive 上传到 YouTube 也会发生同样的情况.

当我在上传的视频上单击“编辑”按钮时,我们会转到此 url https://www.youtube.com/edit?o=U&video_id=XXX 和在“视频信息”列中有“原始文件:未知”。

enter image description here

所有上传的视频文件都有正常的标题,它们是 video/mp4 mime 类型。

我在 Google Drive API 上没有找到任何关于如何更改它的信息。 它可以与文件同名而不是“unknown”吗?

最佳答案

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

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

关于php - 将视频文件上传/导入到 Youtube 后 - 获取 [原始文件 : unknown],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30228272/

相关文章:

php - Laravel 表单方法 get - url 参数

Android YouTube API : Can't reinitialize YouTubePlayerFragment with new YouTube video

youtube - 有什么方法可以获取YouTube视频的Uri字符串吗?

youtube - YouTube Player无法与Android透明面板菜单一起使用

javascript - Google API 示例未加载

php - 您可以让您的用户通过Youtube api上传视频吗?

javascript - 获取视频列表 youtube api

javascript - 如何使这个 CSS 联系表单与 javascript 一起工作?

php - 迁移的意外行为 :refresh command laravel

php - MySQLi multi_query 不工作