タイトルが読み次第、YouTubeのアップロード機能を介してビデオファイルをアップロードして処理することができます。ただし、プログラムで(OAuth2とYouTube API v3を介して)アップロードしようとすると、常に0%パーセントの処理でスタックします。SOにYouTuberはいますか?アップロードの問題に関する特別なフォーラムはありますか?(PS、結果のない同様の質問があります。)
更新されたエラー:深く掘り下げて、それはビデオメタデータに関連しているようです。次のエラーが発生することがあります。
再開可能なアップロードを開始できませんでした(HTTP 400:youtube.video、リクエストメタデータで無効な動画タイトルが指定されています)。
残念ながら、YouTubeのAPI v3のエラーページは実際には語漏に悩まされていません...エラーの意味を知っている人はいますか?
更新されたコード:現時点では、ファイルはチャンクごとにアップロードされます(通常はかなりうまく機能しますが、常にではありません):
function uploadFile($dbfile) {
$client = $this->client;
$youtube = new Google_Service_YouTube($client);
$htmlBody = "";
try {
// 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($dbfile->displayname);
// Numeric video category. See
// https://developers.google.com/youtube/v3/docs/videoCategories/list
$snippet->setCategoryId("22");
// Set the video's status to "private"
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "private";
// Associate the snippet and status objects with a new video resource.
$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);
// Create a MediaFileUpload object for resumable uploads.
$media = new Google_Http_MediaFileUpload(
$client,
$insertRequest,
'video/*',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($dbfile->localfile));
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($dbfile->localfile, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
$client->setDefer(false);
$log = array("success" => true, "snippet_id" => $status["id"]);
} catch (Google_ServiceException $e) {
$log = array("success" => false, "errormsg" => $e->getMessage());
} catch (Google_Exception $e) {
$log = array("success" => false, "errormsg" => $e->getMessage());
}
return $log;
}
それでは、ビデオが処理されないという他の問題があるかもしれませんが、私のものは、挿入されるビデオのタイトルが単に長すぎるということでした。YouTubeの制限は100文字以内です。より長いビデオタイトルを挿入しようとすると、上記の例外がスローされます。おそらく、APIドキュメントのどこかにこれを書き留めておく必要があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加