我正在从这里完成教程:https://developers.google.com/apps-script/api/quickstart/js。当我尝试使用客户端ID和API密钥插入在窗口平台上本地运行quickstart.html时,它会在第144行引发错误:
Uncaught SyntaxError:无效或意外的令牌。
中定义handleClientLoad
未捕获的ReferenceError:未在HTMLScriptElement.onload
在完成此快速入门之前,我是否遗漏了其他需要启用的内容?
答案 0 :(得分:0)
我认为Google示例脚本中存在一些问题。 我发现和修改的是,
您可能希望使用async属性,但快速修复是删除异步并添加第一个和第二个脚本标记的延迟。
<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"
这似乎是转义语法错误和网页中示例代码的换行符处理的组合。以下是我修改的代码的工作片段。
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\"}"
}]
示例代码在callScriptFunction
内调用不存在的updateSigninStatus
。它必须是callAppsScript
,但后者需要一个参数。
我将调用callScriptFunction();
替换为以下内容,并且有效。
callAppsScript(gapi.auth2.getAuthInstance());
通过进行上述更改,示例可以在服务器端创建新脚本,但在更新时会返回错误。 因此,示例代码中似乎存在更多潜在问题,但这是另一个问题,我认为与原始问题无关。