问题描述
我有一个在Google Apps脚本中创建jSon响应的服务
$ p $函数doGet(e){
返回ContentService
.createTextOutput(mcpher.getRestLibrary()。serialize())
.setMimeType(ContentService.MimeType.JSON);
}
这可以在
当我在浏览器上运行它,或者使用firefox RESTclient,它会给出正确的响应。然而,当我在VBA中使用httpGET时,或者在Google Apps脚本中使用httpGET时
function restTest(){
var x = UrlFetchApp.fetch(http://script.google.com/a/macros/mcpher.com/s/AKfycbzLqpnQ2ey8CKAMmzchb2n2FU-aiae0iTKPzAOfAgEpxGwaJgk/exec);
mcpher.DebugPrint(x);
}
我得到了这个回应..就像登录请求一样
{0:\\\
< html dir = \ltr \> \\\
< head> \\\
< meta name = \robots \content = \\noindex,nofollow \/> \\\
< title> mcpher.com< / title> \\\
< script type = \text / javascript\> \\\
< ;! - \\\
//保持登录页面不被iframes所困。\\\ n ... etc ...
该脚本设置为任何人都可以访问,我是否需要进行身份验证 - 即使我是从同一个浏览器会话运行它的?
它需要设置为任何人都可以访问,包括匿名。你确定这是设置?
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 ?
It needs to be set to anyone can access, including anonymous. Are you sure that's the setting?
这篇关于如何将Google Apps Script ContentService用作REST服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!