Facebook graph api错误UrlFetch失败,因为太多的流量正在发送到指定的URL [英] Facebook graph api error UrlFetch failed because too much traffic is being sent to the specified URL

查看:290
本文介绍了Facebook graph api错误UrlFetch失败,因为太多的流量正在发送到指定的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Google脚本中的Facebook图形API获取Facebook广告系列。



我有近5500个数据,我试图抓取数据在每10分钟,并在电子表格中添加更新的数据。



代码工作正常。但经过2-3次迭代后,我得到一个错误

  UrlFetch失败,因为太多的流量正在发送到指定的URL 

如果我再次与其他电子邮件分享我的Google脚本,它会在接下来的2-3次迭代中工作,然后再次失败。

我在从

但之后添加选项

  {useIntranet:true} 

我收到请求超时问题。



是否有解决此问题的其他解决方案?我需要每隔10分钟获取一次数据。

解决方案

在使用代码之后,对于每600秒(600分钟)600次呼叫(10分钟)的fb图形API存在限制。但是从谷歌应用程序脚本中调用fb图形API的限制要少得多。这就是为什么当我每10分钟使用jQuery Ajax加载数据时,它可以正常工作,但是当我使用

  UrlFetchApp.fetch 

在Google Apps脚本中,它会在一天内尝试2-3次后阻止我。 / p>

因此,由于限制是来自谷歌应用程序脚本的fb图形api,我试图调用其他api而不是fb图形API,它工作,它并没有阻止我。

因此,我创建了一个节点js服务器,如: -

pre $ var express = require(express),
app = express(),
cors = require('cors'),
bodyParser = require('body-parser'),
request = require('request');
app.use(cors());

app.use(bodyParser.json()); //支持JSON编码的主体
app.use(bodyParser.urlencoded({//支持URL编码的主体
extended:true
}));
$ b $ app.get(/ test,function(req,res){
res.send(Test success);
})
app。 post('/ getFbFeed',function(req,res){
//使用节点的请求模块向fb api发送请求,fb提要url来自
//前端作为请求参数
request(req.body.url,function(error,response,body){
if(!error&&& response.statusCode == 200){
res.send (body); //将请求的url的响应发送给前端
}
})
})
app.listen(process.env.PORT || 3000 );

所以这段代码会加载fb graph api的数据,我会发送fb的url在google apps脚本中显示api。



因此,在我写的google apps脚本中, var options =
{
method:post,
payload:{url:url}
};
//发送post请求到带有fb feed url的节点js服务器以加载数据,因为从fb加载数据到google apps脚本的限制。
response = UrlFetchApp.fetch(http://fbfeed-48431.onmodulus.net/getFbFeed,options);


I'm trying to fetch Facebook Ad Campaings using Facebook graph api from Google script.

I've almost 5500 data, and I'm trying to fetch the data in each 10 minutes and add the updated data in a spreadsheet.

The code is working fine. But after 2-3 iteration I'm getting an error

UrlFetch failed because too much traffic is being sent to the specified URL

If I share my Google script with other email again it's working for next 2-3 iteration and then fails again.

I got a solution to add a extra option at the time of fetch data from Previous Stackoverflow Question

But after adding the option

{"useIntranet" : true}

I'm getting request time out issue.

Is there any other solution to fix this issue? I need to fetch the data in each 10 minutes throughout a day.

解决方案

After working more with the code, what I got though there is a limitation for fb graph api like 600 call per 600 seconds(10 minutes). But the limitation for calling fb graph api from google apps script is quite less that it. That's why when I'm loading the data using jQuery Ajax in each 10 minutes it works fine but when I load the same data using

UrlFetchApp.fetch

in google apps scripts it blocks me after 2-3 attempts in a day.

So as the limitation is on fb graph api from google apps script, I tried to call some other api instead of fb graph api and it worked, it didn't blocked me.

So I created a node js server like:-

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);

So this code will load the data from fb graph api, and I'll send the url for fb graph api from the google apps script.

So, in the google apps script I've written

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);

这篇关于Facebook graph api错误UrlFetch失败,因为太多的流量正在发送到指定的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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