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

空扰寡人 提交于 2019-12-11 04:36:51

问题


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.



来源:https://stackoverflow.com/questions/29689968/urlfetch-failed-because-too-much-traffic-is-being-sent-to-the-specified-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!