开发者

Youtube Data API: Retrieving multiple Video entries by IDs in a single request

开发者 https://www.devze.com 2022-12-16 19:52 出处:网络
I am wondering if there is a way to query YouTube for multiple random videos (video id\'s are known) in a single query?

I am wondering if there is a way to query YouTube for multiple random videos (video id's are known) in a single query? I am storing video id'开发者_Go百科s in the local db and need to show multiple details(list with thumbs, rating, author name,etc.) in the web page.

I am looking at the Youtube Data API and see that I can a single entity data like this:

Uri  videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/video_id");
Video video = request.Retrieve<Video>(videoEntryUrl);

Repeating this in the loop seems to be a bad idea, because of the quotas.

There is also "batch processing" available - http://code.google.com/apis/youtube/2.0/developers_guide_dotnet.html#Batch_processing. Seems like I can issue up to 50 random request, but it expects some feed I don't have as a parameter, when executing batch. There is an overload with some Uri, but it is not documented well - google-gdata.googlecode.com/svn/docs/folder59/M_Google_GData_Client_FeedRequest_1_Batch__1_2.htm

Does anybody have any ideas on how to retrieve multiple video entries by id's? Any help would be appreciated.


In Youtube Data API version 3.0 You can do it in a simple way like this.

https://www.googleapis.com/youtube/v3/videos?key=API_KEY&part=snippet&id=video_id1,video_id2

Just add your video ids separated by comma. It will fetch you the data for all videos in JSON

I dont know what is the limit on this, will update the answer once I find it.


I too had exactly the same problem, I needed a list of video objects related to an arbitrary list of video id's, i.e. not conforming to any of the feeds.

The batch processing option is very tempting, but the implementation seems quite heavy for what should be pretty simple functionality.

At the end of the day, doing a basic video search for the id's separated by pipe "|" achieves the required result:

http://gdata.youtube.com/feeds/api/videos?q=h5jKcDH9s64|elzqvWXG1Y

Hope this helps


RobD's answer works well. You can add something like this to the end of the URL to only retrieve the data you actually need, saving some bandwidth:

&fields=entry(id,title)

eg:

http://gdata.youtube.com/feeds/api/videos?q=h5jKcDH9s64|elzqvWXG1Y&fields=entry(id,title)


Here's a clearer explanation for the non PHP people

http://oktryitnow.com/?p=83


You can send multiple requests to youtube data api wrapped in a single request. YouTube allows you to send at most 50 multiple requests in a single request. This kind of request is known as a batch processing request. I have developed a working piece of code specifically for this problem. I had to do same kind of thing for a website I was working on. Anyways you can see how to do it from here (sample code is also present for download): http://www.ovaistariq.net/2010/06/youtube-batch-processing-requests-made-less-costly/

0

精彩评论

暂无评论...
验证码 换一张
取 消