URL事件失败 [英] URLfetch in an event failing

查看:86
本文介绍了URL事件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单元格中有两个组合框,这些组合框由表单中的范围填充。当第一个改变时,我建立一个URL并调用:

  var resp = UrlFetchApp.fetch(url,{method :get,muteHttpExceptions:false}); 

并且它会填充控制第二个组合框的第二个范围。这在调试模式下工作得很好。但我的目标是使用 onEdit 模式工作。如果第一个组合框更改,则该方法运行并填充第二个。使用此语句:

  mydoc.getActiveSheet()。getRange(15,1).setValue(Some debug message); 

我将它放在整个方法中,看看它死在哪里。我在 UrlFetchApp.fetch()方法之后有一个声明,它永远不会写入,所以我知道这就是问题所在。你可以在事件期间进行这些类型的调用吗?

再一次,它可以很好地通过脚本编辑器手动运行,但不能从 onEdit



我看到这个问题他们不允许这样做,但是线程中的最后一个评论说他通过将另一个自定义方法附加到onEdit上来使其工作。我从另一个方法调用 URLFetchApp ,但是我尝试创建一个myOnEdit函数,并从那里调用 URLFetchApp ,但它仍然失败。不知道他是什么意思手动附加到事件...

解决方案

使用一个简单的触发器:




$ b

function onEdit(e){
var response = UrlFetchApp.fetch 'http://www.google.com/');
Logger.log(response.getContentText());
}

我得到以下错误(查看 - >执行记录):

执行失败:您无权调用fetch(第2行,文件代码)[0.008秒总运行时间]

一种可能的解决方法是创建可安装的触发器:

function myOnEdit(e){
var response = UrlFetchApp.fetch('http://www.google。 COM /');
Logger.log(response.getContentText());

$ b $ * b $ b在电子表格中,创建新的触发器:
运行:myOnEdit
事件:从电子表格
开始编辑
* /


I have two combo boxes in cells that are populated by ranges in the sheet. When the first one changes, I build a URL and call:

var resp = UrlFetchApp.fetch(url, {"method": "get","muteHttpExceptions":false});

And it populates a 2nd range which controls the 2nd combo box. This works just fine in debug mode. But my goal is for this to work using the onEdit mode. If the first combo box is changed, the method runs and populates the second. Using this statement:

mydoc.getActiveSheet().getRange(15, 1).setValue("Some debug message");

I have it placed throughout the method to see where it dies. I have a statement right after the UrlFetchApp.fetch() method that never writes, so I know that's where the problem is. Can you make these types of calls during events?

Again, it works just fine running it manually via the script editor, but not when called from onEdit.

I see this question where they do not allow it, but the last comment in the thread said he got it to work by attaching another custom method to onEdit. I call URLFetchApp from another method, but I tried creating a myOnEdit function, and called URLFetchApp from there, but it still fails. Not sure what he meant by manually attaching to the event...

解决方案

Using a simple trigger:

function onEdit(e) {
  var response = UrlFetchApp.fetch('http://www.google.com/');
  Logger.log(response.getContentText());
}

I get the following error (View -> Execution transcript):

Execution failed: You do not have permission to call fetch (line 2, file "Code") [0.008 seconds total runtime]

One possible workaround is to create a installable trigger:

function myOnEdit(e) {
  var response = UrlFetchApp.fetch('http://www.google.com/');
  Logger.log(response.getContentText());
}

/*
In the Spreadsheet, create new trigger:
Run: myOnEdit
Events: From spreadsheet
On edit
*/

这篇关于URL事件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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