Javascript 为什么会出现gapi.client未定义错误?

Javascript 为什么会出现gapi.client未定义错误?,javascript,google-api,Javascript,Google Api,我开始使用谷歌API。我有一个web应用程序,我想连接到谷歌日历。我使用下面的例子,只是为了掌握一些窍门: <html> <head> <script> function appendResults(text) { console.log("***** DEBUG_jwir3: Appending results..."); var results = document.getElementById('r

我开始使用谷歌API。我有一个web应用程序,我想连接到谷歌日历。我使用下面的例子,只是为了掌握一些窍门:

<html>
  <head>
    <script>
      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);
      }
    </script>
    <script src="https://apis.google.com/js/client.js?onload=load"></script>
  </head>
  <body>
    <div id="results"></div>
  </body>
</html>
我不太清楚这里发生了什么。我已经在我的google开发者控制台中启用了urlshortener API。另外,我正在本地主机上运行这个程序,所以我的理解是应该允许所有localhost或file://referer请求。不过,我确实让我的API密钥允许所有引用者使用通配符:*


有没有想过我可能做错了什么

这可能是因为您的浏览器阻止了来自google.com的cookies


我已将Firefox永久设置为阻止Cookie,除非我明确将网站列入白名单。默认情况下,google.com被阻止,我会得到一个空白的google日历,上面有您报告的错误,但日历上显示的是google.com允许的cookies。

还有一件事我忘了提及——如果我查看请求/响应,我会得到google客户端API的javascript,它从定义gapi.client开始,所以我不知道为什么谷歌认为它没有定义,特别是谷歌需要第三方cookie,这些cookie通常与广告跟踪器相关。
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