简体   繁体   English

Javascript Google API快速入门错误

[英]Javascript google API quickstart error

I'm working through the tutorial from here : https://developers.google.com/apps-script/api/quickstart/js . 我正在从这里浏览本教程: https : //developers.google.com/apps-script/api/quickstart/js When i try to run the quickstart.html locally on window platform with client ID and API key insert, it throws an error at line 144 saying: 当我尝试在Windows平台上使用客户端ID和API密钥插入在本地运行quickstart.html时,它在第144行抛出错误:

Uncaught SyntaxError: Invalid or unexpected token. 未捕获的SyntaxError:无效或意外的令牌。
Uncaught ReferenceError: handleClientLoad is not defined at HTMLScriptElement.onload 未捕获的ReferenceError:在HTMLScriptElement.onload中未定义handleClientLoad

Did i miss something else that need to be enable before going through this quickstart? 在进行此快速入门之前,我是否错过了需要启用的其他功能?

I think there are some issues in the Google sample script. 我认为Google示例脚本中存在一些问题。 What I found and modified are, 我发现和修改的是

  1. async and defer attributes on script tag 异步和延迟脚本标签上的属性

You may want to use async attribute, but a quick fix is to remove async and add defer to both the 1st and 2nd script tags. 您可能想使用async属性,但是一个快速的解决方案是删除异步并将defer添加到第一个和第二个脚本标签中。

    <pre id="content"></pre>
    <!-- add defer to the first script tag -->
    <script defer type="text/javascript">
    ...
    <!-- remove async from the 2nd tag -->
    <script defer src="https://apis.google.com/js/api.js"
  1. Syntax Error on Strings inside callAppsScript function. callAppsScript函数内部的字符串语法错误。

This seems that the combination of escaping syntax error and the newline handling of the sample code in the web page. 这似乎是转义语法错误和网页中示例代码的换行处理的结合。 The following is the working fragment of the code I modified. 以下是我修改的代码的工作片段。

    resource: {
          files: [{
            name: 'hello',
            type: 'SERVER_JS',
            source: 'function helloWorld() {\n  console.log("Hello, world!");\n}'
          }, {
            name: 'appsscript',
            type: 'JSON',
            source: "{\"timeZone\":\"America/New_York\",\"exceptionLogging\":\"CLOUD\"}"
          }]
  1. Calling non existing function 调用不存在的函数

The sample code calls callScriptFunction inside updateSigninStatus which does not exist. 该示例代码在callScriptFunction内部调用callScriptFunction ,该updateSigninStatus不存在。 It must be callAppsScript but the latter requires a parameter. 它必须是callAppsScript但后者需要一个参数。

I replaced the calling callScriptFunction(); 我替换了调用callScriptFunction(); to the following, and it worked. 到以下内容,并且有效。

callAppsScript(gapi.auth2.getAuthInstance());

By making above changes, the sample can create a new script on the server-side, but error is returned upon updating it. 通过进行上述更改,该示例可以在服务器端创建一个新脚本,但是在更新脚本时会返回错误。 So it seems that there are some more potential issues in the sample code, but it is another problem, and nothing to do with the original question, I guess. 因此,在示例代码中似乎还有更多潜在的问题,但这是另一个问题,我想这与原始问题无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Sheets API快速入门(v4)问题 - Issue with google sheets API quickstart (v4) 调整 Google Sheets API Node.js Quickstart 以使用我自己的工作表,错误:错误:无法解析范围:类数据!A2:E - Adapting Google Sheets API Node.js Quickstart to work with my own sheet, error: Error: Unable to parse range: Class Data!A2:E App Script Go快速入门修改401错误 - App Script Go Quickstart modification 401 error Google Apps脚本执行API:脚本错误消息:找不到脚本功能:【JavaScript】 - Google Apps Script Execution API: Script error message: Script function not found:【JavaScript】 无法使Firebase Google App脚本快速入门教程正常工作 - Can't Get Firebase Google App Script Quickstart Tutorial to Work 适用于我的 Google Sheets 电子表格的 Python quickstart.py - Python quickstart.py adapted to my Google Sheets spreadsheet 卡在 Quickstart 检查学生参加 Google Meet 课程的情况 - Stuck with Quickstart Check student attendance in Google Meet courses 带有Freshdesk API错误的Google App API - Google app api with freshdesk api error Google脚本Javascript日期错误 - Google Scripts Javascript Date Error Google表格Javascript indexOf错误 - Google Sheets Javascript indexOf error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM