Search code examples
javascriptyoutubegoogle-client

Google YouTube API in JavaScript


I want to call the Google API to access YouTube lists, using the Google documentation I am referencing the script on my web page:

<script src="https://apis.google.com/js/client.js?onload=onClientLoad"></script>
<script>
  function onClientLoad() {
      alert(1);
  }
</script>

The onload function is never called, I am not sure what I am missing?!

I am trying to use the solution with an API KEY, but according to the documentation, I need to provide the API Key after the onClientLoad is called...


Solution

  • Found the answer, it was a honest mistake!

    Needed to change the order of the script tags:

       <script>
          function onClientLoad() {
          alert(1);
          }
       </script>
       <script src="https://apis.google.com/js/client.js?onload=onClientLoad"></script>