UrlFetch failed because too much traffic is being

2019-08-06 09:16发布

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

3条回答
走好不送
2楼-- · 2019-08-06 09:31

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-08-06 09:34

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);
查看更多
神经病院院长
4楼-- · 2019-08-06 09:46

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

查看更多
登录 后发表回答