google-apps-script - 为什么“google.scrpt.run”不适用于 GAS 脚本中的 google 任务身份验证?
问题描述
我google.script.run
在 html 模板文件中使用它,它按我的预期工作得很好。
但在将 oauthScope "https://www.googleapis.com/auth/tasks" 添加到 appsscript.json 文件后它不起作用。
两者之间是否有任何关系或依赖关系?
我需要添加它来管理谷歌任务。
让我分享详细信息。
有 2 个脚本
・用于 GSS 的容器绑定脚本
・上述容器绑定脚本引用的库脚本。库脚本
中的 html 模板・在 html 模板中调用 google.script.run.registerSome()。
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<button onclick="showMessage()">showMessage</button>
<script>
function showMessage () {
google.script.run.showMessage();
}
</script>
</body>
</html>
- 库脚本中的源代码
・在 html 文件上方显示为 GSS 编辑对话框。
function onEdit(e, spreadsheetId) {
const htmlTmpl = HtmlService.createTemplateFromFile('someHtml')
const html = htmlTmpl.evaluate().setWidth(900).setHeight(600)
SpreadsheetApp.getUi().showModalDialog(html, 'title')
}
function showMessage () {
Browser.msgBox('Hello world')
}
- 库中的appsscript.json
・在添加“https://www.googleapis.com/auth/tasks”之前
{
"timeZone": "Asia/Tokyo",
"dependencies": {
},
"webapp": {
"access": "ANYONE",
"executeAs": "USER_ACCESSING"
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.container.ui"
],
"runtimeVersion": "V8"
- 容器绑定脚本
・如果未声明此函数,showMessage is not a function
则在浏览器控制台上输出日志。
・_onEdit 绑定到可安装触发器 onEdit。
(使用一些请求用户授权的过程)
function _onEdit(e) {
// `-` is symbol for library.
_.onEdit()
}
function showMessage () {
//no logic here
}
- 复制
- 将库脚本添加到容器绑定脚本(符号
-
在上面的示例中) - 绑定
_onEdit
功能到可安装的编辑触发器。 - 打开 GSS
- 编辑一些单元格
- 显示对话框
- 按下
showMessage
按钮 Hello world
显示消息- 将 oauthScope“https://www.googleapis.com/auth/tasks”添加到库中的 appsscript.json 文件中。
- 然后,再做3-6个流程
- 不显示消息并
uncaught
输出错误日志。
有人知道是什么原因吗?
谢谢,
解决方案
推荐阅读
- bash - OS X上脚本和命令行之间的空文件的grep -v -f不同
- javascript - 如何使用 d3 js 中的设置将链接添加到表格的每一行?
- wordpress - Wordpress 正在更改我的图像文件名并添加数字(例如 150x150)
- c# - 从桌面应用程序使用 MVC 身份代码
- algorithm - 用最小的移动距离在圆圈中画出最大的区域
- angular - Firepad 和 Codemirror 的 Angular 示例代码
- c# - 如何清除 ChromeDriver 中的所有 cookie
- javascript - DataTable row() 始终未定义,无法获取数据
- java - AES - Java 中的加密和 PHP 中的解密
- javascript - 如何从 AJAX 请求执行 Python 代码?