Simple youtube javascript api 3 request not works -
i've tried write simple youtube request search video youtube javascript api v3.
this source code:
<!doctype html> <html> <head> <script type="text/javascript"> function showresponse(response) { var responsestring = json.stringify(response, '', 2); document.getelementbyid('response').innerhtml += responsestring; } // called automatically when javascript client library loaded. function onclientload() { gapi.client.load('youtube', 'v3', onyoutubeapiload); } // called automatically when youtube api interface loaded function onyoutubeapiload() { // api key intended use in lesson. gapi.client.setapikey('api_key'); search(); } function search() { var request = gapi.client.youtube.search.list({ part: 'snippet', q:'u2' }); // send request api server, // , invoke onsearchrepsonse() response. request.execute(onsearchresponse); } // called automatically response of youtube api request. function onsearchresponse(response) { showresponse(response); } </script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="https://apis.google.com/js/client.js?onload=onclientload" type="text/javascript"></script> </head> <body> <pre id="response"></pre> </body> </html>
when load page on google chrome (updated), nothing happens, page remains blank. have request api key browser apps (with referers) , copied in method gapi.client.setapikey.
anyone can me?
thanks
try example here
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>google ajax search api sample</title> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> // how search through youtube channel aka http://www.youtube.com/members google.load('search', '1'); function onload() { // create search control var searchcontrol = new google.search.searchcontrol(); // results expanded default options = new google.search.searcheroptions(); options.setexpandmode(google.search.searchcontrol.expand_mode_open); // create video searcher , add control searchcontrol.addsearcher(new google.search.videosearch(), options); // draw control onto page searchcontrol.draw(document.getelementbyid("content")); // search searchcontrol.execute("u2"); } google.setonloadcallback(onload); </script> </head> <body style="font-family: arial;border: 0 none;"> <div id="content">loading...</div> </body> </html>
Comments
Post a Comment