Last active
August 2, 2017 04:17
-
-
Save devfaysal/43ccce0a98ea558c35aed30939955677 to your computer and use it in GitHub Desktop.
Get video by channel id - YouTube API v3
This file contains 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
<!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