是否必须使用 Google 模块?在进行更改时,您不会获得太大的灵活性。
为什么不使用YouTube API 的 JSON响应?这样,您就可以完全灵活地通过 JavaScript 获取您想要的视频。
这是您想要的频道的 JSON 提要:https ://gdata.youtube.com/feeds/api/users/tomdesigner777/uploads?v=2&alt=jsonc&max-results=5
更新
这是您可以用来从 YouTube 用户上传频道获取视频的代码。目前,此代码在每次页面刷新时随机输出一个视频:
$(document).ready(function() {
var randNumber = RandNo(1,5);
$.ajax({
type: "POST",
url: "https://gdata.youtube.com/feeds/api/users/tomdesigner777/uploads?v=2&alt=jsonc&max-results=5",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function(result) {
var data = result.data;
$("#yt").html("<iframe width='560' height='315' src='http://www.youtube.com/embed/" + data.items[randNumber].id + "' frameborder='0' allowfullscreen></iframe>");
}
});
});
function RandNo(min,max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
完整的解决方案:http: //jsfiddle.net/sbhomra/kCSsX/