javascript - “ScriptError:需要授权才能执行该操作。” 从库运行 google.script.run 时
问题描述
问候,
我发现了几个关于此错误的问题:
"ScriptError: Authorisation is required to perform that action."
但我找不到与我的问题有关的问题。
我想要做的是使用 google.script.run 从 .html 文件调用函数 .gs 文件,其中两个文件都在库中。参考这个答案,这个答案和这个错误报告,我在使用库的脚本中创建了“包装函数”,但仍然未能完成执行。
这是我所做的:
.html 在库中:
<html>
<head>
<script>
function onFailure(error) {
console.log("ERROR: " + error);
}
function myfunc() {
console.log("HERE");
google.script.run.withFailureHandler(onFailure).callLibraryFunction('LibraryName.test', ['test123']);
}
</script>
</head>
<body>
<button onclick="myfunc()">CLICK</button>
</body>
</html>
.gs 在库中
function test(x){
Logger.log(x);
}
.gs 在使用库的脚本中:
function callLibraryFunction(func, args) {
var arr = func.split(".");
var libName = arr[0];
var libFunc = arr[1];
args = args || [];
return this[libName][libFunc].apply(this, args);
}
控制台记录HERE
但随后它记录ERROR: ScriptError: Authorisation is required to perform that action.
而不是预期的输出,test123
.
注意:HTML 用于表格中的自定义无模式对话框,不适用于 Web 应用程序。
我真的希望有人能在这方面帮助我。先感谢您。
解决方案
您需要授予对库“LibraryName”的访问权限作为您的 Gmail 帐户中的授权应用程序,就像您授予对调用脚本的访问权限一样。HtmlService.createHtmlOutputFromFile(...)
我猜你已经在你的库中调用了这个方法。这需要更多的授权。您需要授予此权限。您可以做的是在具有HtmlService.createHtmlOutputFromFile(..)
. 从脚本编辑器运行它并出现授权要求窗口。继续授予访问权限...
推荐阅读
- sql - 如何根据列中的值禁用 oracle apex 中的链接
- python - 在 sympy 中获取复杂表达式的系数
- tensorflow - 在 TensorFlow 中联合训练多个不同的数据集
- python - 在 matplotlib 中使用 plt.Circle 设置 AxisArtist 的轴限制
- powershell - 如何在 System.Windows.Forms.TextBox powershell 中获得焦点?
- ckan - CKAN API 调用以返回 CKAN 网站上所有资源视图的元数据
- python - Python 最佳实践 - 我应该用值初始化变量吗?
- javascript - javascript 中类的每个对象都保存其函数的副本还是只有一个?
- amazon-web-services - 如何通过 reactivesearch-proxy-server 连接到 AWS 上的 ElasticSearch
- c# - Android.Util.AndroidRuntimeException:
发生了