[英]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, 我发现和修改的是
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"
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\"}"
}]
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.