title: Why am I getting a gapi.client undefined error?
body: <p>I'm starting to use Google APIs. I have a web app that I'd like to connect to google calendar. I'm using the following example, just to get the hang of things:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script&gt;
        function appendResults(text) {
          console.log("***** DEBUG_jwir3: Appending results...");
          var results = document.getElementById('results');
          results.appendChild(document.createElement('P'));
          results.appendChild(document.createTextNode(text));
        }
  
        function makeRequest() {
          console.log("***** DEBUG_jwir3: Making request...");
          var request = gapi.client.urlshortener.url.get({
            'shortUrl': 'http://goo.gl/fbsS'
          });
          request.execute(function(response) {
            appendResults(response.longUrl);
          });
        }
  
        function load() {
          console.log("***** DEBUG_jwir3: Loading....");
          gapi.client.setApiKey('AIzaSyDkiyjtUnxlzQUyxnu0WqUtkhyV8Q2KyA0');
          gapi.client.load('urlshortener', 'v1', makeRequest);
        }
      &lt;/script&gt;
      &lt;script src="https://apis.google.com/js/client.js?onload=load"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="results"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Most of this code is taken directly from <a href="https://developers.google.com/api-client-library/javascript/samples/samples#LoadinganAPIandMakingaRequest" rel="nofollow">https://developers.google.com/api-client-library/javascript/samples/samples#LoadinganAPIandMakingaRequest</a> but I modified it a bit to output some data about what's going on. I am getting the following:</p>
  
  <pre><code>GET https://apis.google.com/js/client.js [HTTP/1.1 200 OK 71ms]
  The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. test.html
  GET https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en.pjG1qAV7lig.O/m=client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AItRSTOwlG0qQ6tB8ZQLSqOIeICvIpAiTw/cb=gapi.loaded_0 [HTTP/1.1 200 OK 657ms]
  TypeError: gapi.client is undefined test.html:23
  GET https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en.pjG1qAV7lig.O/m=debug_error/exm=client/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AItRSTOwlG0qQ6tB8ZQLSqOIeICvIpAiTw/cb=gapi.loaded_1 [HTTP/1.1 200 OK 44ms]
  "***** DEBUG_jwir3: Loading...." test.html:22
  TypeError: c is undefined
  </code></pre>
  
  <p>I'm not quite sure what's going on here. I've enabled the urlshortener API in my google developer console. Also, I'm running this from a localhost machine, so my understanding is that all localhost or file:// referrer requests should be allowed. I did make my API key allow all referrers, though, with a wildcard: *. </p>
  
  <p>Any thoughts on what I might be doing wrong? </p>