一天中调用的服务太多次:urlfetch [英] Service invoked too many times for one day: urlfetch

查看:68
本文介绍了一天中调用的服务太多次:urlfetch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格加载项中出现以下错误:

I am getting the following error in my Sheets Add-on:

Service invoked too many times for one day: urlfetch

我知道此处的限制,但是如何能否确定我是达到了100,000的"URLFetch调用"还是达到了100mB的"URLFetch收到的数据"?这是两个截然不同的问题,如果我碰到第一个问题,那么我肯定是在某个地方无意间发出了请求,因为我不可能每天故意打10万次电话.我可能达到了100mb,但是错误的表达方式使我觉得我正在达到第一个,是否有办法确定我要打到哪个?

I'm aware of the limits here, but how can I tell if I am hitting the "URLFetch calls" of 100,000 or the "URLFetch data received" of 100mB? They are two very different issues and if I'm hitting the first one, I must be making requests unintentionally somewhere because there's no way I'm intentionally making the call 100k times a day. It is possible I'm hitting the 100mb, but the way the error is phrased makes me think I'm hitting the first, is there anyway to know for sure which one I'm hitting?

推荐答案

我也遇到了这个问题.我只有1000行要访问Web服务.我的工作表和服务中的数据都没有改变.但是在今天的某个时候,我的大多数单元格都显示#Error与该原因有关.

I have run into that too. I only have 1000 rows going out to a web service. Data did not change neither in my sheet nor in the service. But at some point today most of my cells show #Error with this cause.

我觉得要以太频繁的方式重新获取结果.没有一些可以使用的缓存吗?

I feel like it's going out to re-fetch the results way too often. Is there not some caching that can be employed?

更新(需要较长时间):完全需要添加缓存.因此,我实现了一个使用缓存的函数fetch(url),从而避免了重复调用.

UPDATE (long time due): adding cache was exactly what was needed. So I implemented a function fetch(url) which uses a cache and that way avoids the replicate calls.

function fetch(url) {
  var cache = CacheService.getScriptCache();
  var result = cache.get(url);
  if(!result) {
    var response = UrlFetchApp.fetch(url);
    result = response.getContentText();
    cache.put(url, result, 21600);
  }
  return result;
}

这篇关于一天中调用的服务太多次:urlfetch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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