YouTube GData API returning error 400 when uploading a video

May 14th, 2008 – 11:03 am
Filed as: code

I’ve been battling with the YouTube API for the last 2 days now and found the single line of code that has been preventing me from generating a form upload token.

I was following the example code at http://code.google.com/apis/youtube/developers_guide_php.html#UploadingVideos and kept receiving “Expected response code 200, got 400″ when calling the getFormUploadToken function. HTTP error code 400 is a bad request which wasn’t really much help.

Eventually I found the problem and I will own up straight away that it was basically my fault, I’d made what I considered to be a slight change to the example code, I changed

$mediaGroup->category = array(  $yt->newMediaCategory()->setText('Autos')->setScheme
('http://gdata.youtube.com/schemas/2007/categories.cat'),

$yt->newMediaCategory()->setText('mydevelopertag')->setScheme
('http://gdata.youtube.com/schemas/2007/developertags.cat'),

$yt->newMediaCategory()->setText('anotherdevelopertag')->setScheme
('http://gdata.youtube.com/schemas/2007/developertags.cat')

);

to the following

$mediaGroup->category = $yt->newMediaCategory()->setText('Autos')->setScheme
('http://gdata.youtube.com/schemas/2007/categories.cat');

because I wasn’t interested in multiple categories, just something simple. My mistake was not in removing the two developer tags but removing the array(). This took me almost an entire day to realise and resulted in a “You have to be kidding” comment from me once fixed. *Sigh* oh well, not going to get that time back but at least I learned not to mess with example code.

No Comments

» Leave a comment now

» RSS feed for comments on this post
» TrackBack URI

No comments yet.


Leave a Comment

  1. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>