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