GAS“您无权调用openById” [英] GAS "You do not have permission to call openById"
问题描述
问题:运行脚本时,Google告诉我, 您无权调用openById。
Problem: When I run the script, Google tells me, "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.
GAS文档对可能不起作用的原因一无所知:
GAS documentation says nothing about reasons why it might not be working:
另一个GAS文档说它应该对我有用,因为我是从自定义菜单调用它的:
Another GAS documentation says that it should work for me because I invoke it from a custom menu:
https: //developers.google.com/apps-script/g uides / 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 Script函数编写自定义
函数的过程。菜单触发的功能会在必要时要求用户
授权,因此可以使用所有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);
};
推荐答案
我认为我会提出类似的问题我遇到了这个问题,在这里我收到错误您无权通过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/services/authorization
删除 @OnlyCurrentDoc
为我解决了此问题
这篇关于GAS“您无权调用openById”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!