我有一个谷歌文档插件,它被编程为在文档打开后立即打开侧边栏。当然,这需要在文档中安装并启用插件。
我看到,一周以来,在我们的用例中非常有用的侧边栏自动打开功能不再起作用。
在 StackDriver 日志中,我看到了这个报告:
onOpen(): {authMode=LIMITED, source=Document, user=}
publi-2.0.72-2017-11-27-18-57 [this is the publication version tag]
2017-11-27T18:02:50.126Z : show menu
2017-11-27T18:02:50.180Z : show sidebar
Error showing sidebar Exception: You do not have permission to call showSidebar
2017-11-27T18:02:50.283Z : end onOpen
很明显,根据插件授权生命周期,插件处于 LIMITED 模式,showSidebar() 应该成功(只需查看表中的 LIMITED 列)。
--> 我怀疑最近引入了错误或新的安全限制。
为了记录,这里是一个代码片段:
/**
* Basic setup. At the beginning:
* 1. Add a "Add-ons" menu item.
* 2. Display the doxMaster sidebar.
*/
function onOpen(e) {
console.log("onOpen(): ",e)
console.log(addonversion);
doServerLog("show menu");
showMenu();
doServerLog("show sidebar");
showSidebar();
doServerLog("end onOpen");
}
/**
* Creates the Add-ons menu at the google drive panel.
*/
function showMenu() {
DocumentApp.getUi().createAddonMenu()
.addItem(translate("sidebarMenu"), showSidebar.name)
.addItem(translate("joinFollowingParagraph"), insertJoinFollowingParaSymbol.name)
.addItem(translate("importDocument"), importDocument.name)
.addItem(translate("about"), about.name)
.addToUi();
}
/**
* Creates a doxMaster Add-on Sidebar.
*/
function showSidebar() {
try {
var htmlTemplate = HtmlService.createTemplateFromFile('sidebar');
var html = htmlTemplate.evaluate().setTitle(translate("appTitle"));
DocumentApp.getUi().showSidebar(html);
}
catch (e) {
console.log("Error showing sidebar ", e); // Add-on has not been enabled in this document
}
}