无法在“已为当前用户安装"配置下测试加载项(即AuthMode.NONE) [英] Unable to test add-on under 'Installed for current user' config (i.e. AuthMode.NONE)

查看:134
本文介绍了无法在“已为当前用户安装"配置下测试加载项(即AuthMode.NONE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建我的第一个编辑器附加组件,在该附加组件中,应该在Docs,Sheets和Slides上使用相同的代码库.

I'm trying to build my first editor add-on where the same codebase is supposed to work on Docs, Sheets and Slides.

我仍处于测试阶段,这就是我遇到的障碍.问题出在这里-

I'm still in the testing phases and that's where I've hit a roadblock. Here's the problem -

根据安装与启用,如果要选择一个测试配置作为已为当前用户安装(但尚未启用),则菜单应该是可见的AuthMode.NONE下);但是,根据我的脚本,它向我抛出一个错误,该错误指示-

As per the documentation for Installed versus enabled, if one were to select a test config as Installed for current user (but not yet enabled it), the Menu is supposed to be visible (this would be under AuthMode.NONE); however, per my script, its throwing me an error that indicates -

Google Apps脚本:您无权执行该操作.

Google Apps Script: You do not have permission to perform that action.

...并且菜单也不可见.

... and the Menu is not visible either.

注意:应该在浏览器控制台上查看此错误

这是代码库和清单文件-

Here's the codebase and manifest files -

var fileUI = SpreadsheetApp.getActiveSpreadsheet() ? SpreadsheetApp.getUi() : (DocumentApp.getActiveDocument() ? DocumentApp.getUi() : (SlidesApp.getActivePresentation() ? SlidesApp.getUi() : false));

function onInstall(e) {
  onOpen(e);
}

function onOpen(e) {
  if (fileUI) {
    var menu = fileUI.createAddonMenu();
    if (e && e.authMode == ScriptApp.AuthMode.NONE) {
      menu.addItem('Please Login', 'login');
    } else {
      menu.addItem('Hurray', 'itWorks');
    }
    menu.addToUi();
  }
}

function login() {
  fileUI.alert('Please login to access this add-on');
}

function itWorks() {
  fileUI.alert('Hurray! It works');
}

appscript.json(清单文件)

{
  "timeZone": "Asia/Kolkata",
  "dependencies": {
  },
  "oauthScopes": [
    "https://www.googleapis.com/auth/documents.currentonly",
    "https://www.googleapis.com/auth/presentations.currentonly",
    "https://www.googleapis.com/auth/spreadsheets.currentonly"
  ],
  "exceptionLogging": "STACKDRIVER"
}

备注

  • 在其他两个配置条件(其中两个都具有AuthMode.LIMITED)下进行测试时,附加组件可以完美工作:
    • 在当前文档中启用
    • 已安装并启用
    • Remarks

      • Add-on works perfectly when tested under the other two config criteria (where both have AuthMode.LIMITED):
        • Enabled in current document
        • Installed and enabled
        • 我有一种感觉,我在这里错过了一些超基本的东西.如果我已跳过涵盖此内容的文档的某些部分,我深表歉意.任何帮助,将不胜感激.谢谢.

          I have a feeling that I'm missing something super basic here. I apologize if I've skipped over some part of the documentation that covers this. Any help would be appreciated. Thanks.

          编辑笔记:

          1. 在oauthScopes上添加了第三条评论
          2. 澄清了菜单不可见的问题

          推荐答案

          将脚本文件加载到内存中以执行任何功能(onOpen或任何其他功能)时,将加载/执行所有全局变量.您的问题源于试图在AuthMode.None下获取活动(getActive*())文档的原因.

          When a script file is loaded into memory for execution of any function (onOpen or any other function), all global variables are loaded/executed. Your issue stems from attempting to get the active(getActive*()) document under AuthMode.None.

          var fileUI = SpreadsheetApp.getActiveSpreadsheet() ? SpreadsheetApp.getUi() : (DocumentApp.getActiveDocument() ? DocumentApp.getUi() : (SlidesApp.getActivePresentation() ? SlidesApp.getUi() : false));
          

          参考:

          • 授权模式 -访问文档:在AuthMode下为否":无"表

            Reference:

            • Authorization modes - Access to document: No under AuthMode: "NONE" table

              相关答案-可能无效.

              这篇关于无法在“已为当前用户安装"配置下测试加载项(即AuthMode.NONE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆