0

Al right guys, this drives crazy - much crazy.. trying to build an Internet app (its a school project) using the benefits of YOUTUBE DATA, clients would type a query string in input-search and results displayed - results in json- my code will read this response and displaying it in a DOM ELEMENT div and h1.

Chrome shows me the error on

var request = gapi.client.youtube.***search.list***...

I Tried:

<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../static/content/ClientFinePage.css" />


    <!--First Test -->
    <script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>




    <!--Third Test With YouTube-->
    <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>



    <script src="../static/scripts/ClientFinePage.js"></script> 
</head>



//this element dom for displaying results in results
<input class="search" name="searching" id="searchit" placeholder="Search..." />
<input type="button" id="search-button" onclick="SearchFromYouTube2()" class="search-button" value="" />
<div id="wrapper">
     <iframe id="ytplayer" type="text/html" width="640" height="390"
                        src="http://www.youtube.com/embed/JeLPCETf0Ic"
                        frameborder="0" />

            <div id="results">

            </div>


        </div>
//this script at the end of the file
 <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=init"></script>

AND my js file ClientFinePage.js:

function SearchFromYouTube2() {
    var q = $('#searchit').val();


    gapi.client.setApiKey(apiKey_sucker);
    gapi.client.load('youtube', 'v3', function () {
        isLoad = true;
    });

    var request = gapi.client.youtube.***search.list***({ //<<< *error is here*
        q: q,
        part: 'snippet',
        order: 'date'
    });

    request.execute(function (response) {
        var str = JSON.stringify(response.result);
        $('#results').html('<pre>' + str + '</pre>');
    });
}

I have followed tutorials about using youtube search feature,but still keep receiving this Error

NOTE: changing the location of the script link to google api - putting at the end of the file cause

Uncaught TypeError: Cannot read property 'gapi' of undefined

mplungjan
  • 169,008
  • 28
  • 173
  • 236

0 Answers0