我目前可以从我的频道中获取最新的YouTube视频,但我想将其更改为显示最后3个,但我似乎可以让它发挥作用。
我目前正在使用这个JavaScript:
<script type="text/javascript">
function showVideo(response) {
if(response.data && response.data.items) {
var items = response.data.items;
if(items.length>0) {
var item = items[0];
var videoid = "http://www.youtube.com/embed/"+item.id;
console.log("Latest ID: '"+videoid+"'");
var video = "<iframe width='420' height='315' class='posvid' src='"+videoid+"' frameborder='0' allowfullscreen></iframe>";
$('#static_video').html(video);
}
}
}
</script>
<script type="text/javascript" src="https://gdata.youtube.com/feeds/api/users/gezzamondoTV/uploads?max-results=1&orderby=published&v=2&alt=jsonc&callback=showVideo"></script>
这是最近的视频,有人知道添加或更改什么才能获得最近的3个视频吗?
首先将URL中的max-results=1参数设置为3。
然后编写如下javascript:
<script type="text/javascript">
function showVideo(response) {
if(response.data && response.data.items) {
var items = response.data.items;
for(var i=0;i<items.length;i++) {
var item = items[i];
var videoid = "http://www.youtube.com/embed/"+item.id;
console.log("Latest ID: '"+videoid+"'");
var video = "<iframe width='420' height='315' class='posvid' src='"+videoid+"' frameborder='0' allowfullscreen></iframe>";
$('#static_video'+i).html(video);
}
}
}
</script>
<script type="text/javascript" src="https://gdata.youtube.com/feeds/api/users/gezzamondoTV/uploads?max-results=3&orderby=published&v=2&alt=jsonc&callback=showVideo"></script>
然后在html中,显示如下三个视频:
<div id="static_video0"><h2>Video 1</h2></div>
<div id="static_video1"><h2>Video 2</h2></div>
<div id="static_video2"><h2>Video 3</h2></div>