I am new to GAS and I was trying to pull data from a Google spreadsheet using vizualizations query. The URI works perfect in a browser, and the spreadsheet has been published. But, the response from UrlFetchApp doesn’t make sense since the data is published, no auth needed. here is my code:
function test () {
var url = 'https://docs.google.com/a/1ins.us/spreadsheet/tq?&key=<secretkey>&alt=json';
var q = '&tq=Select S,count(A) Where A is not Null Group By S pivot N';
var data = UrlFetchApp.fetch(url+q).getContentText();
data = data.slice(39,-2); //remove the callback function, is there a way to exec the function?
Logger.log(data);
}
here is the error returned in JSON:
{"version":"0.6","status":"error","errors":[{"reason":"user_not_authenticated","message":"User not signed in","detailed_message":"\u003ca target=\u0022_blank\u0022 href=\u0022https://docs.google.com/spreadsheet/\u0022\u003eSign in\u003c/a\u003e"}]}
What am I missing?
I read that google does not want Google.Visualizations used in GAS. Is this a consideration to this problem?
My guess is that the spreadsheet is not open to the public. Try accessing the URL in an incognito window and see if it prompts you to login. Some domains don’t allow data to be shared outside the domain.