例外:无法从此上下文调用SpreadsheetApp.getUi 第1行

问题描述

我有一个包含两个脚本的项目,该项目已绑定到Google电子表格。 第一个脚本打开用户界面

    var ui = SpreadsheetApp.getUi();
var userProperties = PropertiesService.getUserProperties();

const TOKEN_OLD = 'api.token_old';

function onOpen(){

  ui.createMenu('CREDENZIALI')
  .addItem('Imposta TOKEN','setToken')
  .addToUi();
}

function setToken(){
  var scriptValue = ui.prompt('Per favore inserisci il token.',ui.ButtonSet.OK);
  userProperties.setProperty(TOKEN_OLD,scriptValue.getResponseText());
}

第二个是执行业务逻辑并实现一个自定义功能,该功能将用于电子表格中。

function getFromApi(book_id,dato) {...}

很明显,此API位于身份验证的后面,我不想将令牌硬编码到脚本中,因此我创建了第一个UI,以便最终用户在运行时对其进行管理。

UI可以正常工作,但是当我尝试调用自定义函数时,出现以下错误:

enter image description here

我是文件的所有者。我想念什么?

解决方法

尝试分别在 PDF().cachedFromUrl( 'http://africau.edu/images/default/sample.pdf',placeholder: (progress) => Center(child: Text('$progress %')) ) SpreadsheetApp.getUi();内添加onOpen()

以下脚本可以独立运行:

setToken()

但是,您不能使用自定义公式来调用此函数。查看相关文章:

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...