gpt4 book ai didi

google-apps-script - 我可以在 Google Apps 脚本中测试 DocumentProperties 吗?

转载 作者:行者123 更新时间:2023-12-02 00:45:55 26 4
gpt4 key购买 nike

是否可以测试使用 DocumentProperties 的 Google Apps 脚本? testing documentation似乎表明这是可能的:

If your add-on uses the Properties service, properties will persist and remain available the next time the test configuration is run.

但是,当我尝试使用 DocumentProperties 时,出现以下错误:

Google Apps Script: You do not have permission to call getDocumentProperties

这是我正在尝试的代码:

function appFolderExists(){
PropertiesService.getDocumentProperties().getProperties();
return true;
}

function onOpen() {
FormApp.getUi().createMenu('My Addon')
.addItem('My Addon', 'showSidebar')
.addToUi();
if(!appFolderExists()){
createAppFolder();
}
}

我的插件当前部署为测试(用于表单)。它已安装但未启用。

我想在 appFolderExists 中添加更多逻辑,但由于看不到访问 DocumentProperties,我一直卡住了。我做错了什么或者这只是测试插件的不便限制?

最佳答案

此问题是由于测试加载项已安装但未启用引起的。因此在 authmode.None 中运行代码,在此模式下您无法访问文档属性

解决方法:
1) 在安装和启用时运行测试
2)确定authmode并运行相关代码:

function open(e){

if (e.authMode == ScriptApp.AuthMode.NONE){
// Code that does not access document properties
} else {
var prop = PropertiesService.getDocumentProperties().getProperties();
// Some code that uses document properties
}
}

关于google-apps-script - 我可以在 Google Apps 脚本中测试 DocumentProperties 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43883266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com