0

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.

Community
  • 1
  • 1
Indranil Mondal
  • 2,799
  • 3
  • 25
  • 40

2 Answers2

3

This is not a problem with your call but the number of calls you are making. You might have to reduce that a little. As you can see here, the limit is to make 600 call per 600 seconds(10 minutes). So, depending on what you're fetching, how and in what what quantity although, I feel your description is enough to make me feel sure that the reason you are able to make 2-3 iterations is because by the end of the 3rd one you have exceeded the 1 call/second rate and it is basically shutting you off from there.

I'd also suggest for you to take a look at this page for some more rate-limiting information related to the Facebook Graph API.

Community
  • 1
  • 1
pointNclick
  • 1,584
  • 1
  • 12
  • 17
  • But the problem is, I'm sending 60-70 url fetch call in each 10 minutes. Another problem is once I got the issue even if I try to fetch the data after one hour I'm still getting the issue. – Indranil Mondal Jun 23 '15 at 19:18
  • It also matters what kind of calls you are making. Not every call has the same expense. For example, look at point 4 on [here](https://developers.facebook.com/docs/marketing-api/api-rate-limiting#adsapilimit), on the page I shared with you earlier. If I may quote, "Updates are 10~100 more expensive than creates". Similarly, each kind of request differs in terms of "expense". – pointNclick Jun 23 '15 at 20:11
  • According to the doc there is a limit of 600 calls per 600 secs. And the limit is for a single ip & single token. So if I call from a different IP or user different token then I'll be getting the data again. But instead of this share my code with some other email and execute the code from that email it works though the token or ip is not changed. How it's possible! – Indranil Mondal Jun 25 '15 at 13:51
  • Not only this, if I write a javascript code, and load data using ajax request, then it's working fine, not limit issue. But when I'm trying to load data by Google apps script using UrlFetch then I'm getting the error after 2-3 iteration. – Indranil Mondal Jun 25 '15 at 14:26
  • In that case, take a look at [this](https://script.google.com/dashboard). Hence, you're probably hitting your daily quota limits depending on what kinda account you're running the script through. Which is why shifting to another account, re-runs your script with a problem. – pointNclick Jun 25 '15 at 16:49
0

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);
Indranil Mondal
  • 2,799
  • 3
  • 25
  • 40