Skip to content

Instantly share code, notes, and snippets.

@devfaysal
Last active August 2, 2017 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devfaysal/43ccce0a98ea558c35aed30939955677 to your computer and use it in GitHub Desktop.
Save devfaysal/43ccce0a98ea558c35aed30939955677 to your computer and use it in GitHub Desktop.
Get video by channel id - YouTube API v3
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul id="list"></ul>
<script
src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>
<script>
apiKey = 'YOUR_API_KEY';
console.log('apiKey');
$(document).ready(function(){
$.get(
"https://www.googleapis.com/youtube/v3/channels",{
part: 'contentDetails',
id: 'UC29ju8bIPH5as8OGnQzwJyA',
key: apiKey
},
function(data){
$.each(data.items, function(i, item){
console.log(item);
pid = item.contentDetails.relatedPlaylists.uploads;
console.log(pid);
getVideo(pid);
});
}
);
function getVideo (pid){
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems",{
part: 'snippet',
maxResults: 10,
playlistId: pid,
key: apiKey
},
function(data){
var output;
$.each(data.items, function(i, item){
console.log(item);
vidTitle = item.snippet.title;
output = '<li>'+vidTitle+'</li>';
$('#list').append(output);
});
}
);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment