How to Search for YouTube Content?

Here’s a sample code snippet that illustrates a simple approach to search for YouTube content. This example searches for YouTube Videos that is related to Gangnam Style.

The example code has two parts (a) HTML – Search.html (b) JAVASCRIPT – Search.js. Check them out.

(a) Search.html that invokes

(b) Search.js
// Your use of the YouTube API must comply with the Terms of Service:

// 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 to get a key for your own applications.


function search() {
// Use the JavaScript client library to create a search.list() API call.
var request ={
part: ‘snippet’, q:’gangnamstyle’


// Send the request to the API server,
// and invoke onSearchRepsonse() with the response.

// Called automatically with the response of the YouTube API request.
function onSearchResponse(response) {


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s