OpenByUrl引发错误:您无权调用openByUrl(第39行,文件“代码”) [英] OpenByUrl throwing error: You do not have permission to call openByUrl (line 39, file "Code")

查看:780
本文介绍了OpenByUrl引发错误:您无权调用openByUrl(第39行,文件“代码”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Google电子表格中有一个脚本,用于打开Goog​​le文档并将表格中的文本返回到表格的某个单元格中,如下所示:

  function getItemStatus(docUrl){
var doc = DocumentApp.openByUrl(docUrl);
var docBody = doc.getBody();
var docTbls = docBody.getTables();
var itmTbl = docTbls [0];
var itmStatus = itmTbl.getCell(3,1).getText();
返回itmStatus;
}

当我尝试在电子表格中运行该函数时,它返回此错误:
$ b


错误:您没有权限调用openByUrl(第39行,文件代码)


如果我创建另一个函数来直接调用上述函数,它会工作得很好,并返回我之后的值。

  function testItemGet(){
var docUrl =(...);
itmStr = getItemStatus(docUrl);
Logger.log(该项目的值为+ itmStr)
}

生成的日志文件:


[13-07-17 19:27:39:130 EDT]开始执行



[13-07-17 19:27:39:387 EDT] DocumentApp.openByUrl([...])[0.253秒]

[13-07-17 19:27:39:388 EDT] Document.getBody()[0秒]

[13-07-17 19: 27:39:388 EDT] Body.getTables()[0秒]



[13-07-17 19:27:39:38 EDT] Table.getCell( [3,1])[0秒] $ b

[13-07-17 19:27:39:389 EDT] TableCell.getText()[0 seconds]



[13-07-17 19:27:39:389 EDT] Logger.clear()[0 seconds]
Logger.log([该项目的值为Deferred,[]])[0秒]

[13-07-17 19:27:39:390 EDT]执行成功[总运行时间为0.256秒]

我已经Google了,只要我有编辑或o我应该可以做到这一点。



我对Google Apps脚本非常新,所以请保持温柔。 :)



感谢您提前给予的帮助和耐心!

自定义函数以有限的权限运行,并且不能利用依赖于用户凭证的服务,包括DocumentApp。

https://developers.google.com/apps-script/execution_custom_functions#permissions


I have a script in my Google spreadsheet that opens a Google Doc and returns the text in a certain cell of a table, as follows:

function getItemStatus(docUrl) {
   var doc = DocumentApp.openByUrl(docUrl);
   var docBody = doc.getBody();
   var docTbls = docBody.getTables();
   var itmTbl = docTbls[0];
   var itmStatus = itmTbl.getCell(3,1).getText();
   return itmStatus;  
}

When I attempt to run the function in my spreadsheet, it returns this error:

error: You do not have permission to call openByUrl (line 39, file "Code")

If I create another function to call the above function directly it works just fine and returns the value I am after.

function testItemGet() {
   var docUrl = ("...");
   itmStr = getItemStatus(docUrl);
   Logger.log("The item's value is " + itmStr)
}

Resulting log file:

[13-07-17 19:27:39:130 EDT] Starting execution

[13-07-17 19:27:39:387 EDT] DocumentApp.openByUrl([...]) [0.253 seconds]

[13-07-17 19:27:39:388 EDT] Document.getBody() [0 seconds]

[13-07-17 19:27:39:388 EDT] Body.getTables() [0 seconds]

[13-07-17 19:27:39:388 EDT] Table.getCell([3, 1]) [0 seconds]

[13-07-17 19:27:39:389 EDT] TableCell.getText() [0 seconds]

[13-07-17 19:27:39:389 EDT] Logger.clear() [0 seconds]

[13-07-17 19:27:39:389 EDT] Logger.log([The item's value is Deferred , []]) [0 seconds]

[13-07-17 19:27:39:390 EDT] Execution succeeded [0.256 seconds total runtime]

From what I have Googled, as long as I have edit or owner rights to the document I should be able to do this.

I am pretty new to Google Apps Scripting so please be gentle. :)

Thank you ahead of time for your help and patience!

解决方案

Custom functions run with limited permissions, and cannot take advantages of services that rely on user credentials, including DocumentApp.

https://developers.google.com/apps-script/execution_custom_functions#permissions

这篇关于OpenByUrl引发错误:您无权调用openByUrl(第39行,文件“代码”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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