Post large video to youtube via google php client api v3

前端 未结 1 2011
天涯浪人
天涯浪人 2020-12-17 04:25

I am trying to upload large videos to youtube via the latest version of the google client api (v3, latest checked out source)

I have it posting the videos, but the

相关标签:
1条回答
  • 2020-12-17 05:02

    It looks like this use case wasn't supported before. Here's a sample that works with the very latest version of the Google APIs PHP client (from https://code.google.com/p/google-api-php-client/source/checkout).

    if ($client->getAccessToken()) {
      $videoPath = "path/to/foo.mp4";
      $snippet = new Google_VideoSnippet();
      $snippet->setTitle("Test title2");
      $snippet->setDescription("Test descrition");
      $snippet->setTags(array("tag1", "tag2"));
      $snippet->setCategoryId("22");
    
      $status = new Google_VideoStatus();
      $status->privacyStatus = "private";
    
      $video = new Google_Video();
      $video->setSnippet($snippet);
      $video->setStatus($status);
    
      $chunkSizeBytes = 1 * 1024 * 1024;
      $media = new Google_MediaFileUpload('video/mp4', null, true, $chunkSizeBytes);
      $media->setFileSize(filesize($videoPath));
    
      $result = $youtube->videos->insert("status,snippet", $video,
          array('mediaUpload' => $media));
    
      $status = false;
      $handle = fopen($videoPath, "rb");
      while (!$status && !feof($handle)) {
        $chunk = fread($handle, $chunkSizeBytes);
        $uploadStatus = $media->nextChunk($result, $chunk);
      }
    
      fclose($handle);
    }
    
    0 讨论(0)
提交回复
热议问题