2015-09-29 5 views
9

タイトルが読み取られると、YouTubeのアップロード機能を使用して動画ファイルをアップロードして処理することができます。ただし、プログラムで(OAuth2とYouTube API v3を使用して)プログラムをアップロードしようとすると、処理は常に0%に止まります。あなたには、どなたでも参加できますか?アップロードに関する特別なフォーラムはありますか? (PS、ない結果とsimilar questionがあります。)YouTube API経由でアップロードすると動画ファイルが0%でスタックされる

UPDATED ERROR:深く掘り、ビデオのメタデータに関連すると思われます。残念ながら

the error page for YouTube's API v3はしていません:(youtube.video、 要求メタデータが無効なビデオタイトルを指定します。HTTP 400)

は再開可能なアップロードを開始できませんでした:私はときどき、次のエラーを得ますか本当にlogorrhoeaに苦しんで...誰でもエラーが何を意味知っていますか?

更新されたコード:ファイルが(通常はすべての回はかなりうまく動作しますが、ない)チャンクでチャンクをアップロードされた瞬間

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; 
    } 
+0

あなたは[MCVE](http://stackoverflow.com/help/mcve)を投稿する必要があります。どのように正確にプログラムでこれをやっていますか? – approxiblue

+0

質問を更新し、問題のコードを添付しました。 – Jan

+1

インターネット接続は安定していますか?あなたは信頼性の低い接続でより良い回復のために 'chunkSizeBytes'を低く設定したいかもしれません。それ以外に、問題が発生する可能性がある場所について私が考えることができる唯一の他の場所は、ファイルサイズを設定するときです。デバッグを試して、どこがうんざりしているのかをよりよく知ることができましたか? –

答えて

3

それでは、動画と他の問題があるかもしれません処理されていませんが、私が挿入するビデオのタイトルは単に長すぎました。 YouTubeの制限はで100文字以下です。長いビデオタイトルを挿入しようとすると、上記の例外がスローされます。 APIドキュメントのどこかでこれを書き留めておくべきでしょう。

関連する問題