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
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.