Google API Sample not Loading

65 views Asked by At

I'm trying to use the sample code from: https://developers.google.com/youtube/analytics/v1/sample-application

However, when I open the HTML file it just won't load. Firebug says "google is not defined" and references line 17 of the index.js file, which is:

google.load('visualization', '1.0', {'packages': ['corechart']});

This leads me to believe that something isn't loading or isn't finished loading by the time index.js is. I read some other similar posts that talked about forcing the browser to wait for scripts to load before moving on, but I'm too novice to understand what they were talking about.

Since I'm copying the sample code exactly for all three files (index.html, index.js, index.css) (Although I add in my OAuth key in index.js) I'm hoping you all are able to replicate it yourself and see what I mean.

1

There are 1 answers

0
leonm On

You need to import the Google jsapi before you attempt to load the visualisation package. Make sure the following line appears early in your document:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

If you copy paste the entire contents of the online example it works properly.