Update youtube channel fetching javascript to work with API v3

110 Views Asked by At

I used the following js file to grab all the videos from my youtube channel to display them on my website. Since youtube updated their API to v3, this code doesn't work anymore. I'm not really versed in js, but I found this code in a tut and tweaked it a little to get it to work. Is there something I can add to this to make it work again or do I have to write a whole new function?

function vidinfolist(data) {
    var dat = data.feed.entry;
    var pageOutput = '<ul>';
    for (var i=0; i<data.feed.entry.length; i++) {
    var datID=dat[i].id.$t.substring(38);
    var datTitle=dat[i].title.$t;
    var datDescription=dat[i].media$group.media$description.$t;
    var datThumbnail=dat[i].media$group.media$thumbnail[0].url;
    pageOutput += '<li><h2>' + datTitle + '</h2>';
    pageOutput += '<li><p>' + datDescription + '</p>';
    pageOutput += '<div class="g-ytsubscribe sub-btn" data-channel="channelNameHere" data-layout="default"></div>';
    pageOutput+='<iframe width="635" height="360" src="http://www.youtube.com/embed/'+datID+'?wmode=transparent&amp;HD=0&amp;rel=0&amp;showinfo=0&amp;controls=1&amp;fs=1&amp;autoplay=0" width= frameborder="0" allowfullscreen></iframe></li>';
    }
    document.getElementById('videoCode').innerHTML = pageOutput;
    pageOutput +='</ul>';
}
1

There are 1 best solutions below

0
On

Check out the V3 code samples (search for "upload") to get the videos from your channel.

The basic logic is to use your channel ID to get the ID for your uploads playlist, then get the videos from that.