您无权调用openById [英] You do not have permission to call openById
问题描述
问题:运行脚本时,Google告诉我
Problem: When I run the script, Google tells me,
您无权调用openById
You do not have permission to call openById
我已经从另一个Google电子表格中复制了一个脚本,并更改了 target_ssKey 变量的单元格引用,并在源和目标电子表格中创建了大小适当的命名范围.
I had copied a script from another one of my Google spreadsheets and changed the target_ssKey variable's cell reference and created properly-sized Named Ranges in both the Source and Target spreadsheets.
Google Apps脚本文档对可能无法正常工作的原因一无所知:
Google Apps Script documentation says nothing about reasons why it might not be working:
另一个Google Apps脚本文档说它应该对我有用,因为我是从自定义菜单中调用它的:
Another Google Apps Script documentation says that it should work for me because I invoke it from a custom menu:
https://developers.google.com/apps-script/guides/sheets/functions#using_apps_script_services
上面的第二个链接说:
如果您的自定义函数抛出错误消息,则 您没有 允许调用X服务. ,该服务需要用户授权 因此无法在自定义函数中使用.
If your custom function throws the error message You do not have permission to call X service., the service requires user authorization and thus cannot be used in a custom function.
要使用除上面列出的服务以外的其他服务,请创建一个自定义菜单 运行Apps脚本功能而不是编写自定义 功能.从菜单触发的功能将询问用户 必要时进行授权,因此可以使用所有应用程序 脚本服务.
To use a service other than those listed above, create a custom menu that runs an Apps Script function instead of writing a custom function. A function that is triggered from a menu will ask the user for authorization if necessary and can consequently use all Apps Script services.
我尝试将函数放入自定义函数"项目中,然后放入附加"项目中,但仍然收到相同的错误消息.
I tried putting the function into a "Custom Functions" project and then into an "Add-on" project, but still got the same error message.
关于我做错了什么以及如何进行这项工作的任何想法?
Any ideas on what I am doing wrong and how to make this work?
这是我的确切代码:
function exportData_SStoSS() {
// Get the source data.
var source_ss = SpreadsheetApp.getActiveSpreadsheet();
var data = source_ss.getRangeByName("exportData").getValues();
// Identify the target.
var controls_sh = source_ss.getSheetByName("Controls");
var target_ssKey = controls_sh.getRange('C2').getValue();
var target_ss = SpreadsheetApp.openById(target_ssKey);
// Paste the data to the target.
target_ss.getRangeByName("importData").setValues(data);
};
推荐答案
我认为我会遇到类似的问题,这使我想到了这个问题,在此我收到了错误You don't have permission to call by openById
.就我而言,我试图从translate.gs
调用函数,该函数是从本示例中复制的:
I thought that I would throw in a similar issue that I had which brought me to this question, where I received the error You don't have permission to call by openById
. In my case I was trying to call functions from translate.gs
which I copied from this example:
https://developers.google.com/apps-script/quickstart/docs
请注意,在translate.gs
/**
* @OnlyCurrentDoc
*
* The above comment directs Apps Script to limit the scope of file
* access for this add-on. It specifies that this add-on will only
* attempt to read or modify the files in which the add-on is used,
* and not all of the user's files. The authorization request message
* presented to users will reflect this limited scope.
*/
罪魁祸首是@OnlyCurrentDoc
注释.请参阅此处以供参考:
The culprit here is the @OnlyCurrentDoc
comment. See here for reference:
https://developers.google.com/apps-script/guides/服务/授权
删除@OnlyCurrentDoc
为我解决了此问题
这篇关于您无权调用openById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!