Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch request with youtube api - get the latest video information from multiple channels

I have 10 youtube channels that I like and I want to get the latest video information for each channel. Right now i'm doing 10 different calls like this one:

http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&alt=jsonc&start-index=1&max-results=1

I want to replace those 10 calls with a single one by using a batch request.

I tryed this:

String xml = "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:batch='http://schemas.google.com/gdata/batch'>" +
             "    <batch:operation type='query'/>" +
             "    <entry>" +
             "        <id>http://gdata.youtube.com/feeds/api/videos/VIDEO_ID_1</id>" +
             "    </entry>" +
             "    <entry>" +
             "        <id>http://gdata.youtube.com/feeds/api/videos/VIDEO_ID_2</id>" +
             "    </entry>" +
             ...
             "    <entry>" +
             "        <id>http://gdata.youtube.com/feeds/api/videos/VIDEO_ID_10</id>" +
             "    </entry>" +
             "</feed>";

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://gdata.youtube.com/feeds/api/videos/batch?v=2");
StringEntity se = new StringEntity(xml);
se.setContentType("text/xml");
httpPost.setEntity(se);
HttpResponse response = httpClient.execute(httpPost);

I'm getting a XML with usefull data in the HTTPResponse object.

But if I want to get the 10 latest videos information, I won't know the videoId.

Does anybody know how to achieve this ?

like image 266
Matthieu Coisne Avatar asked Dec 06 '12 07:12

Matthieu Coisne


People also ask

What data can you get from YouTube API?

You can retrieve entire playlists, users' uploads, and even search results using the YouTube API. You can also add YouTube functionalities to your website so that users can upload videos and manage channel subscriptions straight from your website or app.

How often does YouTube API update?

Standard feeds are updated periodically, with the update frequency varying from feed to feed. Many feeds are updated every 30 to 40 minutes but other feeds such as those that capture daily, weekly or monthly results – may only be updated hourly or even daily. Check the link above for more information.

What is snippet in YouTube API?

The snippet object contains basic details about the video, such as its title, description, and category. The date and time that the video was published.


1 Answers

You can't make a batch request that includes 10 different http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2 URLs in the request body.

You would need to request http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&max-results=1 10 times, once with each USERNAME.

Alternatively, if you have some sort server-side process that's interested in finding out when new videos are uploaded to a given channel, you can use either PubSubHubbub or SUP to handle that scenario more efficiently. Because your question was tagged with android I'm assuming that you care about doing this client-side, though.

like image 172
Jeff Posnick Avatar answered Oct 05 '22 12:10

Jeff Posnick