开发者

Youtube - getting information from feed

I am currently calling a youtube playlist using:

http://gdata.youtube.com/feeds/api/videos?q=USERNAME&v=2&alt=jsonc&callback=function

I was just wondering if there was a more thorough feed, I need to be able to collect how many ratings a video has - whereas this just开发者_StackOverflow tells me if ratings are allowed...thanks.


I do not see any rating details inside the feed you mentioned. Nevertheless, it is possible to request another feed that contains the required information. Here is example code that you can place inside a HMTL page that includes jQuery 1.4 or later:

<!-- Don't forget to insert jQuery inside <head> section -->
<ol id="videos">
</ol>
<script type="text/javascript">
function processFeed(videosFeed) {
    for (var i = 0; i < videosFeed.data.items.length && i < 10; i++) {
        var item = videosFeed.data.items[i];
        var li = $("<li/>").html("loading data for video id " + item.id + "...").appendTo("#videos");
        $.getJSON("http://gdata.youtube.com/feeds/api/videos/" + item.id + "?v=2&alt=jsonc&callback=?", (function(el) {
            return function(videoFeed) {
                el.html(videoFeed.data.title + "<br>Views: " + videoFeed.data.viewCount + "<br>Rating: " + videoFeed.data.rating + " out of 5<br>From: " + videoFeed.data.ratingCount + " ratings");
            };
        })(li));
    }
}
</script>
<script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos?q=sesame street&v=2&alt=jsonc&callback=processFeed"></script>

I've set up a jsFiddle demo here. You may also find some useful information here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜