Getting data for multiple videos using the YouTube API

In: Uncategorized

8 Mar 2012

This took me a lot longer then it should have to figure out and I thought I’d throw it up here in case anyone else wanted to do it.

The issue was that I had a list of YouTube video IDs and I wanted to see what category they were all in. I didn’t want to do a request for each video ID so I wanted to find a way to get data using one request. The way to do it is to use the YouTube API Batch Processing.

Post this XML:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:yt="http://gdata.youtube.com/schemas/2007">

<batch:operation type="query" />
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/hLQl3WQQoQ0</id>
</entry>
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/SkTt9k4Y-a8</id>
</entry>
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/pRpeEdMmmQ0</id>
</entry>
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/2FM4UPrAjnc</id>
</entry>
</feed>

to this URL:
http://gdata.youtube.com/feeds/api/videos/batch

and that’s it. Notice the URL in each ID node: the last path item is the ID of the YouTube video.

2 Responses to Getting data for multiple videos using the YouTube API

Avatar

roy

June 20th, 2012 at 12:30 pm

hey dude!
thanks a lot!
i was looking for this solution!

do u have any idea how i cant do it with jquery $.post?

somthing like:

[code]

$.post(

‘http://gdata.youtube.com/feeds/api/videos/batch’,

{???},

function(data){

console.log(data);

}

);

[/code]

how should i pass the xml as key:value object?
thanks a lot!

Avatar

Khanh

June 21st, 2012 at 2:23 pm

Thanks for the script, this helped out quite a bit. How do you pass a developers key into this batch process?

http://gdata.youtube.com/feeds/api/videos/nukVGzNGAhc?v=2&key=keyvalue

Will return the data by itself. But when I append the key/value pair as part of the request string, my script bottoms out.

Comment Form

About this blog

Nothing that notable about this blog. It's just going to be a place where we post random stuff.

Photostream

  • free cccam: Ola great share. I think the best cccam server are those from fishbone cloud I would like to see [...]
  • FirstSam: I see you don't monetize your blog, don't waste your traffic, you can earn additional cash every m [...]
  • Arv: In else case it should invoke: super.writeText(writer, text); NOT writer.write(text); [...]
  • Chand: Hi could any one suggest, if few childs should be CDATA and dynamic value... How to get this with X [...]
  • Andrew: This is definitely a great start to the solution I need, but I need CDATA tags to be added dynamical [...]