由于安装了应用程序后未显示的“菜单选项”,因此无法发布Google Editor Addon...。错误

发布于 2025-02-05 11:35:46 字数 1741 浏览 2 评论 0 原文

我正在尝试将我的Google Sheet插件发布到Google Workspace。评论后,我收到了一封电子邮件,其中包含以下反馈:

菜单 - 安装应用程序后未显示的菜单选项。请确保该附加组件正确使用OnInstall()和onopen()填充其菜单。菜单项首次安装后以及打开其他文件时填充菜单项。请参阅编辑器附加授权。 , https://devevela -ons/Concepts/Editor-Auth-lifecycle

我添加了菜单,它在测试模式下工作,但我被困在此评论过程中。

的代码。

function onInstall(e) {
  onOpen(e);
}
var userProperties = PropertiesService.getUserProperties();

function onOpen(e) {
// Adding menu to addons menu
if (e && e.authMode != ScriptApp.AuthMode.NONE)
{
    SpreadsheetApp.getUi()
    .createAddonMenu()
    .addItem('Enable/Disable', 'showSidebar')
    .addSeparator()
    .addItem('History ', 'openHistoryDialog')
    .addSeparator()
    .addItem('Buy credits', 'addCredits')
    .addSeparator()
    .addItem('Settings', 'settingsDialog')
    .addToUi();

    // Default value for enable or disable.
    userProperties.setProperty("enable_user", false);
  }
}

{
  "timeZone": "Asia/Karachi",
  "dependencies": {
  "enabledAdvancedServices": [
  {
    "userSymbol": "Sheets",
    "serviceId": "sheets",
    "version": "v4"
  }
]
},
   "exceptionLogging": "STACKDRIVER",
   "oauthScopes": [
     "https://www.googleapis.com/auth/spreadsheets",
     "https://www.googleapis.com/auth/userinfo.email",
     "https://www.googleapis.com/auth/userinfo.profile",
     "https://www.googleapis.com/auth/script.external_request",
     "https://www.googleapis.com/auth/script.container.ui",
     "https://www.googleapis.com/auth/script.locale"
],
    "runtimeVersion": "V8"
}

是一些代码

I am trying the publish my Google sheet addon to Google Workspace. After the review I got an email with following feedback:

Menu - Menu options not shown after App is installed. Please ensure that the add-on correctly uses onInstall() and onOpen() to populate its menu. The menu items populate when the add-on is first installed and when a different file is opened. See Editor add-on authorization. , https://developers.google.com/workspace/add-ons/concepts/editor-auth-lifecycle

I added the the menu and it's working in test mode but I am stuck in this review process.

Here's some code of Code.gs file:

function onInstall(e) {
  onOpen(e);
}
var userProperties = PropertiesService.getUserProperties();

function onOpen(e) {
// Adding menu to addons menu
if (e && e.authMode != ScriptApp.AuthMode.NONE)
{
    SpreadsheetApp.getUi()
    .createAddonMenu()
    .addItem('Enable/Disable', 'showSidebar')
    .addSeparator()
    .addItem('History ', 'openHistoryDialog')
    .addSeparator()
    .addItem('Buy credits', 'addCredits')
    .addSeparator()
    .addItem('Settings', 'settingsDialog')
    .addToUi();

    // Default value for enable or disable.
    userProperties.setProperty("enable_user", false);
  }
}

and here appscript.json

{
  "timeZone": "Asia/Karachi",
  "dependencies": {
  "enabledAdvancedServices": [
  {
    "userSymbol": "Sheets",
    "serviceId": "sheets",
    "version": "v4"
  }
]
},
   "exceptionLogging": "STACKDRIVER",
   "oauthScopes": [
     "https://www.googleapis.com/auth/spreadsheets",
     "https://www.googleapis.com/auth/userinfo.email",
     "https://www.googleapis.com/auth/userinfo.profile",
     "https://www.googleapis.com/auth/script.external_request",
     "https://www.googleapis.com/auth/script.container.ui",
     "https://www.googleapis.com/auth/script.locale"
],
    "runtimeVersion": "V8"
}

thank you for help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡墨 2025-02-12 11:35:46

该问题可能与添加的方式处理菜单有关,当前您的代码中的菜单是在条件语句上显示的,假设事件的状态与 script> scriptapp.authmode.none 但是,如果由于某种原因,此语句失败,则菜单将与菜单项一起显示,他们可能会在提到该行为时参考:

安装应用程序后未显示的菜单选项。请确保该附加组件正确使用OnInstall()和onopen()填充其菜单。菜单项首次安装后以及打开其他文件时填充。

您可以检查在您试图检测授权模式时:

function onOpen(e) {
  var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp.
  if (e && e.authMode == ScriptApp.AuthMode.NONE) {
    // Add a normal menu item (works in all authorization modes).
    menu.addItem('Start workflow', 'startWorkflow');
  } else {
    // Add a menu item based on properties (doesn't work in AuthMode.NONE).
    var properties = PropertiesService.getDocumentProperties();
    var workflowStarted = properties.getProperty('workflowStarted');
    if (workflowStarted) {
      menu.addItem('Check workflow status', 'checkWorkflow');
    } else {
      menu.addItem('Start workflow', 'startWorkflow');
    }
  }
  menu.addToUi();
}

请注意,在分析处理当前授权模式的条件语句之前正在创建菜单。

The problem might be related with the way that the Add on is handling the menu, currently the menu in your code is displayed on a conditional statement assuming that the status of the event is different than ScriptApp.AuthMode.NONE however if for some reason this statement fails then the menu will fail to be displayed along with the menu items, they may be referring to that behavior when they mention:

Menu options not shown after App is installed. Please ensure that the add-on correctly uses onInstall() and onOpen() to populate its menu. The menu items populate when the add-on is first installed and when a different file is opened.

You could check the example given in the documentation as you are trying to detect the authorization mode:

function onOpen(e) {
  var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp.
  if (e && e.authMode == ScriptApp.AuthMode.NONE) {
    // Add a normal menu item (works in all authorization modes).
    menu.addItem('Start workflow', 'startWorkflow');
  } else {
    // Add a menu item based on properties (doesn't work in AuthMode.NONE).
    var properties = PropertiesService.getDocumentProperties();
    var workflowStarted = properties.getProperty('workflowStarted');
    if (workflowStarted) {
      menu.addItem('Check workflow status', 'checkWorkflow');
    } else {
      menu.addItem('Start workflow', 'startWorkflow');
    }
  }
  menu.addToUi();
}

Notice that the menu is being created before the conditional statement that handles the current authorization mode is analyzed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文