Upload video to Youtube using Youtube API V3 and PHP

后端 未结 4 670
自闭症患者
自闭症患者 2020-12-07 14:46

I am trying to upload a video to Youtube using PHP. I am using Youtube API v3 and I am using the latest checked out source code of Google API PHP Client library.
I am us

4条回答
  •  一生所求
    2020-12-07 15:21

    I also realize this is old, but as I cloned the latest version of php-client from GitHub I ran in to trouble with Google_Service_YouTube_Videos_Resource::insert()-method.

    I would pass an array with "data" => file_get_contents($pathToVideo) and "mimeType" => "video/mp4" set as an argument for the insert()-method, but I still kept getting (400) BadRequest in return.

    Debugging and reading through Google's code i found in \Google\Service\Resource.php there was a check (on lines 179-180) against an array key "uploadType" that would initiate the Google_Http_MediaFielUpload object.

    $part = 'status,snippet';
    $optParams = array(
        "data" => file_get_contents($filename),
        "uploadType" => "media",  // This was needed in my case
        "mimeType" => "video/mp4",
    );
    $response = $youtube->videos->insert($part, $video, $optParams);
    

    If I remember correctly, with version 0.6 of the PHP-api the uploadType argument wasn't needed. This might apply only for the direct upload style and not the resumable upload shown in Any Day's answer.

提交回复
热议问题