How to use Google Apps Script ContentService as a

2019-01-20 19:23发布

问题:

I have a service that creates a jSon response in Google Apps Script

function doGet(e) {
   return ContentService
            .createTextOutput(mcpher.getRestLibrary().serialize())
            .setMimeType(ContentService.MimeType.JSON);
}

This can be found at mcpher.com

When i run it at the browser, or the firefox RESTclient it gives a correct response. However when I use httpGET from within VBA, or as in the example below in Google Apps Script

function restTest() {
  var x = UrlFetchApp.fetch("http://script.google.com/a/macros/mcpher.com/s/AKfycbzLqpnQ2ey8CKAMmzchb2n2FU-aiae0iTKPzAOfAgEpxGwaJgk/exec");
  mcpher.DebugPrint(x);
}

I get this response .. like a request to login

{"0":"\n<html dir=\"ltr\" >\n<head>\n  <meta name=\"robots\" content=\"noindex,nofollow\" />\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n  <title>mcpher.com</title>\n  <script type=\"text/javascript\">\n  <!--\n    // Keep login page from being trapped in iframes.\n  ... etc...

The script is set to anybody can access. Do I somehow have to authenticate - even though I'm running it from the same browser session ?

回答1:

It needs to be set to anyone can access, including anonymous. Are you sure that's the setting?