Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google apps script UrlFetchApp.fetch limitations?

I have a simple script that pulls about 30,000 characters of JSON.

I get SyntaxError: Unexpected token: F (line 12) when I try to parse it with JSON.parse() or Utilities.jsonParse();

function refresh() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  sheet.clear();


  var text = UrlFetchApp.fetch("http://blablah/json");

  Logger.log(text.getContentText());

  //error SyntaxError: Unexpected token: F (line 12)
  json = JSON.parse(text);
)

The logger only shows about 59 lines of the JSON, but I was told that the logger has a space limit - but I'm not so sure that's it.

Running on my own server, JSON.parse parses the data just fine and so does jQuery get().

So I'm thinking UrlFetchApp.fetch() just can't get long files?

Hard to accept and I've found no documentation about it :(

like image 780
Vigrond Avatar asked May 18 '12 02:05

Vigrond


1 Answers

You can check the UrlFetch and other services limitations on the new Apps Script dashboard. From my experience, Logger.log has a much more tighter limitation for a single log than UrlFetch, it's possible that UrlFetch is getting it fine, Logger.log is not showing it and you're running into other problem.

Try placing the getContentText result somewhere else, e.g. a spreadsheet cell. Or split it and call logger log in a for-loop.

A possible error that you might be facing (besides the quota limitation) is character encoding, getContentText has an optional parameter where you might inform the encoding of the page, have you checked that?

like image 170
Henrique G. Abreu Avatar answered Oct 28 '22 06:10

Henrique G. Abreu