Skip to content

Instantly share code, notes, and snippets.

@JamiesonRoberts
Last active August 29, 2015 14:26
Show Gist options
  • Save JamiesonRoberts/23a821a8044276589436 to your computer and use it in GitHub Desktop.
Save JamiesonRoberts/23a821a8044276589436 to your computer and use it in GitHub Desktop.
Simple script to get the videos that are part of a playlist on youtube
var playlistID = 'PLmKbqjSZR8TaNjzkuwaFOqjQibUnS2w6u';
var youtubeKEY = '{YOUR-API-KEY-HERE}';
var playlistJSON;
// This needs to be revised/updated to remove the error for a depreciation
function playListGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( );
return xmlHttp.responseText;
}
function playListRetrevial()
{
return playListGet('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=10&playlistId='+playlistID+"&key="+youtubeKEY);
}
playlistJSON = JSON.parse(playListRetrevial());
var items = playlistJSON.items;
console.log(itemsArray);
window.onload = function() {
for (var i in items) {
var currentVid = items[i].snippet.resourceId.videoId;
console.log(currentVid);
// document.getElementById('video_container').innerHTML += '<li><iframe src="https://www.youtube.com/embed/'+currentVid+'?list='+playlistID+'" frameborder="0" allowfullscreen></iframe></li>'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment