Created
June 9, 2015 14:46
-
-
Save bepatrickdavid/ad7681324ae21ddc373c to your computer and use it in GitHub Desktop.
jQUERY: Get videos of channel youtube api v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="youtube-mychannel"> | |
<ul id="results"></ul> | |
</div> | |
<style> | |
#youtube-mychannel ul { | |
width:100%; | |
} | |
#youtube-mychannel ul li{ | |
list-style:none; | |
width:33%; | |
display:inline-block; | |
padding:20px; | |
} | |
#youtube-mychannel ul li iframe{ | |
width:100%; | |
height:200px; | |
border: none; | |
} | |
#youtube-mychannel ul li .title{ | |
height:60px; | |
float:left; | |
} | |
#youtube-mychannel ul li .video{ | |
height:200px; | |
float:left; | |
width:100%; | |
} | |
@media screen and (max-width:1023px) { | |
#youtube-mychannel ul li{ | |
width:50%; | |
} | |
} | |
@media screen and (max-width:767px) { | |
#youtube-mychannel ul li{ | |
width:100%; | |
} | |
} | |
</style> | |
<script> | |
$(document).ready(function(){ | |
$.get( | |
"https://www.googleapis.com/youtube/v3/channels",{ | |
part: 'contentDetails', | |
forUsername: channelName, | |
key: ApiKey}, | |
function(data) { | |
$.each(data.items, function(i, item) { | |
console.log(item); | |
pid = item.contentDetails.relatedPlaylists.uploads; | |
getVids(pid); | |
}); | |
} | |
); | |
function getVids(pid) { | |
$.get( | |
"https://www.googleapis.com/youtube/v3/playlistItems",{ | |
part: 'snippet', | |
maxResults: 4, | |
playlistId: pid, | |
key: ApiKey }, | |
function(data) { | |
var output; | |
$.each(data.items, function(i, item) { | |
console.log(item); | |
videTitle = item.snippet.title; | |
videoId = item.snippet.resourceId.videoId; | |
output = '<li><iframe src=\"//www.youtube.com/embed/'+videoId+'\"></iframe>'+videTitle+'</li>'; | |
$('#results').append(output); | |
}); | |
} | |
); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment