1
votes

I've been trying to access the API through a Google Script and get a rate limit 403 after just one request (actually zero, since I never get any info in the response). This occurs with and without credential use. The API works fine when I access it through cURL or the browser.

Here's my request: https://api.github.com/repos/moodle/moodle/compare/e7c8da0fb83c6bbd818fec967d...b5f3ed32a690e46fc0ad3b251

The error: " Truncated server response: {"message":"API rate limit exceeded for 107.178.195.128. (But here's the good news: Authenticated requests get a higher rate limit. Check out the d..."

The following request shows that I have zero requests left, which makes no sense since I've only made five, maybe.

function myFunctionA() {
  var url = "https://api.github.com/rate_limit";    

  //var url = "https://api.github.com/repos/moodle/moodle/compare/e7c8da0fb83c6bbd818fec967d...b5f3ed32a690e46fc0ad3b251";
  var response = UrlFetchApp.fetch(url);         
  var json = response.getContentText();
  var data = JSON.parse(json);
  Logger.log(data);
}

Logs

[16-09-19 10:13:48:745 CDT]
{rate=
 {limit=60, reset=1474300805, remaining=0},
  resources=
  {core=
     {limit=60, reset=1474300805, remaining=0},
   search=
    {limit=10, reset=1474298088, remaining=10}}}

2

2 Answers

0
votes

The difference between your code and curl (+browser) request is the useragent string. From your code I can't see any user string you are passing. Although I didn't use UrlFetchApp before, but it sounds like it doesn't support useragent string.

Here is the response I got when I try to fetch the link without any useragent.

Request forbidden by administrative rules. Please make sure your request has a User-Agent header ...
0
votes

Please note you need exclusive IP. Since google app script uses shared IP addresses, so your problem persists.