javascript 使用 JSON 从 YouTube 频道获取视频列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16632945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting a list of videos from a YouTube channel using JSON
提问by Sam
I am attempting to list the 5 most recent videos (title, updated, thumbnail (hqDefault)) from a channel. I have the data in JSON format, but despite looking at several guides I can not seem to parse it. Any ideas? Can use Javascript or jQuery.
我正在尝试从频道中列出 5 个最近的视频(标题、更新、缩略图(hqDefault))。我有 JSON 格式的数据,但尽管查看了几个指南,但我似乎无法解析它。有任何想法吗?可以使用 Javascript 或 jQuery。
Here's the URL: https://gdata.youtube.com/feeds/api/videos?q=googledevelopers&max-results=5&v=2&alt=jsonc&orderby=published
这是网址:https: //gdata.youtube.com/feeds/api/videos?q=googledevelopers&max-results=5&v=2&alt=jsonc&orderby=published
FWIW here is what I have so far(Disregard HTML formatting)
FWIW 这是我到目前为止所拥有的(忽略 HTML 格式)
$.getJSON('https://gdata.youtube.com/feeds/api/videos?q=googledevelopers&max-results=5&v=2&alt=jsonc&orderby=published', function(data) {
var output="<ul>";
for (var i in data.data.items) {
output+="<li>" + data.data.items[i].title + "</li>";
}
document.getElementById("videos").innerHTML=output;
回答by techfoobar
Once you get the parsed object, you can iterate through it like:
获得解析的对象后,您可以像这样遍历它:
$.getJSON('https://gdata.youtube.com/feeds/api/videos?q=googledevelopers&max-re??sults=5&v=2&alt=jsonc&orderby=published', function(data) {
console.log(data);
for(var i=0; i<data.data.items.length; i++) {
console.log(data.data.items[i].title); // title
console.log(data.data.items[i].description); // description
}
});