Last active
March 30, 2016 09:21
-
-
Save fpigerre/5771735 to your computer and use it in GitHub Desktop.
YouTube API - Searching for YouTube videosCoded in JavaScript
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
// Your use of the YouTube API must comply with the Terms of Service: | |
// https://developers.google.com/youtube/terms | |
// Helper function to display JavaScript value on HTML page. | |
function showResponse(response) { | |
var responseString = JSON.stringify(response, '', 2); | |
document.getElementById('response').innerHTML += responseString; | |
} | |
// Called automatically when JavaScript client library is loaded. | |
function onClientLoad() { | |
gapi.client.load('youtube', 'v3', onYouTubeApiLoad); | |
} | |
// Called automatically when YouTube API interface is loaded (see line 9). | |
function onYouTubeApiLoad() { | |
// This API key is intended for use only in this lesson. | |
// See http://goo.gl/PdPA1 to get a key for your own applications. | |
gapi.client.setApiKey('INSERT API KEY HERE'); | |
search(); | |
} | |
function search() { | |
// Use the JavaScript client library to create a search.list() API call. | |
var request = gapi.client.youtube.search.list({ | |
part: 'snippet' | |
minecraft: 'q' | |
}); | |
// Send the request to the API server, | |
// and invoke onSearchRepsonse() with the response. | |
request.execute(onSearchResponse); | |
} | |
// Called automatically with the response of the YouTube API request. | |
function onSearchResponse(response) { | |
showResponse(response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment