UrlFetch failed because too much traffic is being

2019-08-06 09:13发布

问题:

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

回答1:

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


回答2:

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.



回答3:

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