我正在尝试从Google脚本中获取使用Facebook图形api的Facebook Ad Campaings。
我几乎有5500个数据,我试图在每10分钟内获取数据,并将更新的数据添加到电子表格中。
代码运行良好。但是经过2-3次迭代,我得到了一个错误
UrlFetch failed because too much traffic is being sent to the specified URL如果我再次与其他电子邮件分享我的Google脚本,它将在接下来的2-3次迭代中工作,然后再次失败。
我找到了一个解决方案,在从以前的堆栈溢出问题获取数据时添加一个额外的选项
但是在添加选项之后
{"useIntranet" : true}我有请求暂停的问题。
还有其他解决办法来解决这个问题吗?我需要在一天的每10分钟内获取数据。
发布于 2015-06-26 15:51:14
在更多地使用代码之后,我得到的结果是,fb图形api有一个限制,即每600秒(10分钟)调用600次。但是,从google应用程序脚本调用fb图形api的限制要小得多。这就是为什么当我使用jQuery Ajax在每10分钟加载数据时,工作正常,但是当我使用
UrlFetchApp.fetch在谷歌应用程序脚本中,在一天2到3次尝试之后,它就会阻止我。
因此,由于限制来自google应用程序脚本的fb图形api,我尝试调用其他api,而不是fb图形api,它成功了,它并没有阻止我。
因此,我创建了一个节点js服务器,类似于:-
var express = require("express"),
app = express(),
cors = require('cors'),
bodyParser = require('body-parser'),
request = require('request');
app.use(cors());
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.get("/test",function(req,res){
res.send("Test success");
})
app.post('/getFbFeed', function(req, res) {
// Sending request to fb api using the request modules of node, the fb feed url is coming from
// the frontend as a request parameter.
request(req.body.url, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(body); // Send the response of the requested url to the frontend.
}
})
})
app.listen(process.env.PORT || 3000);因此,这段代码将从fb图形api加载数据,我将从google应用程序脚本发送fb图形api的url。
所以,在我写的google应用程序脚本中
var options =
{
"method" : "post",
"payload" : {"url" : url}
};
// Sending post request to node js server with the fb feed url to load data as there is limit to load data from fb to google apps script.
response = UrlFetchApp.fetch("http://fbfeed-48431.onmodulus.net/getFbFeed",options);https://stackoverflow.com/questions/31006285
复制相似问题