Skip to content

Instantly share code, notes, and snippets.

@muni2explore
Last active May 24, 2022 07:29
Show Gist options
  • Select an option

  • Save muni2explore/a4540b2791c82bd11e65583961a90554 to your computer and use it in GitHub Desktop.

Select an option

Save muni2explore/a4540b2791c82bd11e65583961a90554 to your computer and use it in GitHub Desktop.
Get youtube video list
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for youtube.search.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/code-samples#javascript
*/
function loadClient() {
gapi.client.setApiKey("AIzaSyAgwPsktcm6HhH8sBe3h_KmMGRr3xI-3RU");
return gapi.client.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(function() { console.log("GAPI client loaded for API");execute() },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.youtube.search.list({
"part": [
"snippet"
],
"channelId": "UCiamo0qmdukmY5nS50VOrYQ",
"maxResults": 100,
"order": "date",
"type": [
"video"
]
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load('client',function(){
loadClient()
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment