3
votes

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.

Here's the URL: 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)

    $.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;
1
Seems to very well formatted. Parsed in a breeze. $.getJSON('https://gdata.youtube.com/feeds/api/videos?q=googledevelopers&max-results=5&v=2&alt=jsonc&orderby=published', function(data) { console.log(data); });techfoobar
Yeah it is - I can parse it using the plethora of online tools out there, but I'm just not aware of how I can get individual values (e.g. video title for first video in list).Sam

1 Answers

6
votes

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
    }
});