5

我有一个谷歌文档插件,它被编程为在文档打开后立即打开侧边栏。当然,这需要在文档中安装并启用插件。

我看到,一周以来,在我们的用例中非常有用的侧边栏自动打开功能不再起作用。

在 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
    }
}
4

3 回答 3

1

昨天,我们注意到了与 Yves 完全相同的问题。但是对我们来说,它发生在 Google 表格插件中。

我在 Google 创建了一个问题:https ://issuetracker.google.com/issues/69824548

请加注星标和评论,以便尽快收到!

于 2017-11-28T09:55:46.193 回答
0

来自https://developers.google.com/gsuite/add-ons/concepts/editor-auth-lifecycle

注意:加载项在 AuthMode.LIMITED 中执行时无法打开侧边栏或对话框。您可以使用菜单项打开侧边栏和对话框,因为它们在 AuthMode.FULL 中运行。

来自 onOpen 和 onEdit 中的错误“您无权调用 showSidebar”(来自 Google Apps 脚本问题跟踪器的问题)

状态:无法修复(预期行为) 抱歉,这里的回复延迟。在与工程团队多次交谈后,我们决定不支持在 onOpen 和 onEdit 中打开 UI 元素(侧边栏、对话框)。授权生命周期文档已更新,以明确您只能在这些模式下添加菜单项:

https://developers.google.com/gsuite/add-ons/concepts/addon-authorization#authorization_modes

我们理解这会影响您可以提供的可能的用户体验,对于突然的变化,我们深表歉意。

于 2019-08-14T23:54:11.260 回答
0

我重新测试,我看到:

  • 在安装附加组件时,模式设置为 FULL
  • 然后打开文档模式设置为无
  • 然后打开插件,关闭文档然后重新打开,模式是有限的。

这与预期的生命周期一致,除了:

  • createTemplate 在 LIMITED 模式下失败
  • 在 LIMITED 模式下,事件的 {user=} 没有价值:

08:22:36.457 onOpen(): {authMode=LIMITED, source=Document, user=}

我认为用户权限有些丢失。

于 2017-11-28T07:28:22.420 回答