1

I'm writing a script for Google Sheets that uses Facebook's Graph API to get my data. Everything worked earlier today but suddenly I'm getting an error:

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

I haven't hit any quotas about using UrlFetch because I can still fetch from other urls that are not graph.facebook.com - so the issue appears to be specifically with Facebook.

Script Code

var myClientID = '';
var myClientSecret = '';
var myAccessToken = '';
var graphURL = 'https://graph.facebook.com/v2.3/';

function getPageLikes(campaign_id) {
  var searchParams = '/stats?fields=actions';
  var campaignID = campaign_id;
  var fullURL = graphURL + campaignID + searchParams + '&access_token=' + myAccessToken;
  var fetchResult = UrlFetchApp.fetch(fullURL);
  var campaign = JSON.parse(fetchResult);
  var likes = campaign.data[0].actions.like;
  return likes;
}

Google Sheet Formula

=getWebClicks('E2')
Rubén
  • 34,714
  • 9
  • 70
  • 166
Joel
  • 51
  • 6
  • Possible duplicate of [Facebook graph api error UrlFetch failed because too much traffic is being sent to the specified URL](https://stackoverflow.com/questions/31006285/facebook-graph-api-error-urlfetch-failed-because-too-much-traffic-is-being-sent) – Rubén Mar 01 '18 at 23:39

3 Answers3

2

I discovered a solution after a little more research. I added the 'useIntranet' option as a parameter to fetchResult and that seemed to solve the issue. I imagine the request is now being sent from another resource that doesn't limit requests to Facebook's Graph API.

If anyone can explain why this fixed my problem, that would be great as well!

var options = {"useIntranet" : true};
var fetchResult = UrlFetchApp.fetch(fullURL, options);
Joel
  • 51
  • 6
  • 1
    Solved the issue for me too! Any further information about what is going on here would be great indeed. – Anis Apr 18 '15 at 14:04
  • Today my scripts stopped running - started getting some timeouts and I narrowed it down to this intranet option. Now I really have to understand what's going on. – Joel May 21 '15 at 20:33
  • 1
    I was also getting the same issue but after adding the option "useIntranet" : true I'm getting timeout. If I share my code with some other email id, it's working for some time and then again the URL fetch error. @Joel Is your problem solved? – Indranil Mondal Jun 23 '15 at 15:15
  • 2
    The option 'useIntranet' apparently does not work anymore in my experience. – Mario Jun 24 '15 at 11:30
  • 1
    I ended up setting up a quick laravel app that accepts the same data (access token and ad set id), sends the request to Facebook using Guzzle, and passes it back to Google sheets as json. Was the only solution I could think of since Google won't tell me an error code or why this was happening. – Joel Jun 24 '15 at 16:40
1

I don't have Facebook so I can't try this, replace var fetchResult = UrlFetchApp.fetch(fullURL); with:

do{
  var fetchResult = UrlFetchApp.fetch(fullURL);
}while(fetchResult == 'UrlFetch failed because too much traffic is being sent to the specified URL.');

Or anything that matches this error object.

Kriggs
  • 3,731
  • 1
  • 15
  • 23
  • 1
    Actually, once your add-on / script hits this quota, it's permanent for a couple of days, so the only thing your script would do is potentially making the ban to last longer. – Mario Jun 24 '15 at 11:30
  • 1
    @Mario since he states that only Facebook has the error, it can't be a Ban on the Google side. – Kriggs Jun 24 '15 at 11:42
  • 1
    @Joel is right, the error is raised on the Google side because Google itself enforces a policy to prevent the script from calling to Facebook. And it also seems that this policy is facebook-specific because there is no similar quota enforced on other urls, as for example twitter. – Mario Jun 25 '15 at 11:54
  • 1
    By the way I have opened an issue regarding this: https://code.google.com/p/google-apps-script-issues/issues/detail?id=5176&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component%20Owner – Mario Jun 25 '15 at 11:56
0

The correct answer is: just wait until the ban gets lifted.

Mario
  • 2,619
  • 1
  • 24
  • 22