简体   繁体   English

Google Apps脚本(GAS) - 创建ContentService API以提供来自Google云端硬盘的JSON数据

[英]Google Apps Script (GAS) - Create ContentService API to serve JSON data from Google Drive

Still trying to figure out all the new stuff launched at Google IO 2012. Regarding GAS and ContentService, you are suppose to be able to create an API to serve your content (from Google Drive). 仍在努力弄清楚在Google IO 2012上推出的所有新内容。关于GAS和ContentService,您可以创建一个API来为您的内容提供服务(来自Google云端硬盘)。 A simple example would be like this: 一个简单的例子是这样的:

var jsonData = {
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021"
    },
    "phoneNumber": [
        {
            "type": "home",
            "number": "212 555-1234"
        },
        {
            "type": "fax",
            "number": "646 555-4567"
        }
    ]
}

function doGet(e) {

  var output = ContentService.createTextOutput();
  output.setMimeType(ContentService.MimeType.JSON);
  output.setContent(jsonData);

  return output;

}

Then from a normal web page, hopefully using jQuery Ajax, you should be able to get the Json data? 然后从一个普通的网页,希望使用jQuery Ajax,你应该能够获得Json数据?

What would the simple javascript code look like on the normal (not-GAS) client? 简单的javascript代码在普通(非GAS)客户端上会是什么样子?

Take a look at JSONP to see what it should look like 看看JSONP看看它应该是什么样子

Also, it should be output.setContent(JSON.stringify(jsonData)); 此外,它应该是output.setContent(JSON.stringify(jsonData));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM