0
votes

I'm trying to write sort of a proxy to be able to query a Google Spreadsheet with Google Chart API without giving rights directly to the spreadsheet to people accessing the visualization.

In order to do that, I want to replace the calls like

var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=THE_KEY');
query.send(handleQueryResponse);

by calls of my Apps Script proxy (with JSONP).

I wrote the proxy as following : (I'll add later an option to encapsulate the result in a function - JSONP)

function doGet(e) {
  return ContentService
    .createTextOutput(
      UrlFetchApp
        .fetch("http://spreadsheets.google.com/tq?tq="+e.parameter.q+"&key="+e.parameter.key))
        .setMimeType(ContentService.MimeType.JSON);
}

When trying to get a response, I obtain this error : google.visualization.Query.setResponse({"version":"0.6","status":"error","errors":[{"reason":"user_not_authenticated","message":"User not signed in","detailed_message":"\u003ca target=\u0022_blank\u0022 href=\u0022https://spreadsheets.google.com/spreadsheet/\u0022\u003eSign in\u003c/a\u003e"}]});

like if the user was not authenticated. I think it's weird because my script is deployed as a web app to be executed by my user, who has the rights on the spreadsheet. I guess we must use some OAuth, but I don't know how to authenticate the query that way.

So my question is : How to authenticate a query with Apps Script to access data with the access rights I defined when deploying as web app ?

1

1 Answers

1
votes

See the urlfetch docs. You are missing all the oauth stuff. The way you are doing it will only work for a public ss.