使用jquery/ajax获取给定用户的所有Youtube视频ID [英] use jquery/ajax for Getting ALL Youtube Video ID's for a given user

查看:103
本文介绍了使用jquery/ajax获取给定用户的所有Youtube视频ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取所有YouTube视频ID时遇到问题.

I'm having a problem in getting all Youtube Video id's.

我正在尝试从YouTube获取给定YouTube用户名的所有视频ID,但是问题是YouTube一次仅允许50个结果.获取所有Youtube ID的最佳方法是什么. 这是我现在拥有的代码:

I'm trying to get all video id's from from Youtube for a given Youtube username, but the problem is that youtube allows only 50 results at a time . What is the best way to get all Youtube id. this is the code I have now:

<div id="video"></div>
<script>
   function getYouTubeAllInfo() {
       $.getJSON('http://gdata.youtube.com/feeds/users/Revision3/uploads?alt=json-in-script&callback=?&start-index=1&max-results=49', 
       function(data){
           $.each(data.feed.entry, function(i, item){
               var id = item['id']['$t'];
               id = id.replace("http://gdata.youtube.com/feeds/videos/",""); 
               $("#video").append('<div id="'+id+'"> ['+id+'] ['+i+'] ');
               $("#video").append('</div>');
           });
       }); 
   }

 $(document).ready(function () {
     getYouTubeAllInfo();
 });    


</script>

推荐答案

假设您可以获取视频数量,则可以执行以下操作:

Assuming you can get the count of videos, you can do something like this:

int currentIndex = 1
int count = GET_COUNT_SOMEHOW;
while (currentIndex < count) {
           $.getJSON('http://gdata.youtube.com/feeds/users/Revision3/uploads?alt=json-in-script&callback=?&start-index=' + currentIndex + '&max-results=49', 
           function(data){
               $.each(data.feed.entry, function(i, item){
                   var id = item['id']['$t'];
                   id = id.replace("http://gdata.youtube.com/feeds/videos/",""); 
                   $("#video").append('<div id="'+id+'"> ['+id+'] ['+i+'] ');
                   $("#video").append('</div>');
       });
   }); 
    currentIndex += 50;
}

这篇关于使用jquery/ajax获取给定用户的所有Youtube视频ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆