带有表格插件的Google Apps脚本PERMISSION_DENIED [英] Google Apps Script PERMISSION_DENIED with sheets addon
问题描述
我尝试基于此表单,这是我在 Google支持线程
当我复制工作表时,它工作正常,但是当我尝试在实际工作表中放入完全相同的代码时,它不再起作用. 当我尝试从模板中访问GA函数时,它将引发错误.
我创建了一个简化的测试项目,但该项目也无法为我工作.
要重现该错误:
- 通过 https://docs.google.com/spreadsheets/创建新的电子表格
- 创建第二张工作表(左下角标签)并将其命名为类别"
- 在第一列中填写几个字段.内容没关系
- 转到工具->脚本编辑器
在"code.gs"中输入
function doGet() {
var html = HtmlService.createHtmlOutputFromFile('Index')
.setTitle('Multiple selector')
.setWidth(300);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showSidebar(html);
}
function onOpen(e) {
SpreadsheetApp.getUi().createMenu('Index')
.addItem('Show Sidebar', 'doGet')
.addToUi();
doGet();
}
function getOptions() {
var validation = {
sheet: 'CATEGORIES',
range: 'A2:A'
}
Logger.log("running getOptions");
Logger.log(SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues());
return SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues()
.filter(String)
.reduce(function(a, b) {
return a.concat(b)
})
}
并创建一个名为Index.html的第二个文件(HTML文件)
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onFailure(error) {
var div = document.getElementById('output');
div.innerHTML = "ERROR: " + error.message;
}
google.script.run.withFailureHandler(onFailure)
.getOptions();
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>
- 保存项目
- 单击运行->运行功能->"onOpen"(首次运行时,您可能需要授权该应用程序)
现在工作表中应该有一个侧栏,该栏对我来说是错误的PERMISSION_DENIED
即使我在资源->云平台项目中选择一个项目,也无法使用.
奇怪的是,如果我使用原始的链接的(工作中的)电子表格并更改了代码中的某些内容,它将对我不再起作用.
我现在所知道的: -它不适用于我的Gmail或Google Apps帐户 -对于使用同一文档的其他人也可以使用 -如果我禁用Adblocker,仍然无法正常工作 -如果我从隐身模式下访问工作表不起作用 -如果我使用Firefox而不是Chrome
可以正常工作
我想念什么?
我对权限被拒绝"错误消息有相同的问题,我发现了这一点
https://github.com/burnnat/page-sizer/issues/3
我认为问题是我已登录多个Google帐户 当我为此工作时. 我退出了所有Google帐户,然后 仅登录了我尝试使用formMule的一个帐户, 它奏效了.
所以我在chrome中使用隐身模式尝试了完全相同的代码,仅登录了一个帐户,就可以了!
我希望这可以帮助您解决问题.
I tried to implement a simple "Multi selector sidebar" extension based on THIS SHEET which I found in this Google support thread
When I copy the sheet it works fine but when I try to put the exact same code in my real sheet, it doesn't work anymore. It throws an error when I try to access the GA function from within the template.
I have created a simplified test project which also fails to work for me.
To reproduce the error:
- Create a new Spreadsheet at https://docs.google.com/spreadsheets/
- Create a second sheet (tab bottom left) and name it CATEGORIES
- Fill in a few fields in the first column. Content doesn't matter
- Got to Tools -> Script editor
In the "code.gs" enter
function doGet() {
var html = HtmlService.createHtmlOutputFromFile('Index')
.setTitle('Multiple selector')
.setWidth(300);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showSidebar(html);
}
function onOpen(e) {
SpreadsheetApp.getUi().createMenu('Index')
.addItem('Show Sidebar', 'doGet')
.addToUi();
doGet();
}
function getOptions() {
var validation = {
sheet: 'CATEGORIES',
range: 'A2:A'
}
Logger.log("running getOptions");
Logger.log(SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues());
return SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues()
.filter(String)
.reduce(function(a, b) {
return a.concat(b)
})
}
And create a second file (HTML file) called Index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onFailure(error) {
var div = document.getElementById('output');
div.innerHTML = "ERROR: " + error.message;
}
google.script.run.withFailureHandler(onFailure)
.getOptions();
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>
- Save the project
- Click Run-> Run function -> "onOpen" (on first run you'll probably need to authorize the application)
Now in the sheet there should be a sidebar which opens with an error for me PERMISSION_DENIED
Even when I select a project at Resources -> Cloud platform project it won't work.
Oddly enough if I use the original linked (working) spreadsheet and change something in the code, it won't work anymore for me.
Things I know by now: - It doesn't work with my gmail or google apps account - For other people using the same document it works - Still doesn't work if I disable Adblocker - Doesn't work if I access the sheet from incognito mode - It does work if I use Firefox instead of Chrome
What am I missing?
I have the same issue with the "permission denied" error message, and I found this
https://github.com/burnnat/page-sizer/issues/3
I think the issue is that I'm logged into multiple google accounts when I am working on this. I logged out of all google accounts, then only logged into the one account that I was trying to use formMule and it worked.
so I tried the exactly same code with incognito mode in the chrome, with only one account logged in, and it works !
I hope this can help you with your issue.
这篇关于带有表格插件的Google Apps脚本PERMISSION_DENIED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!