【问题标题】:Google Apps Script (GAS) - Create ContentService API to serve JSON data from Google DriveGoogle Apps 脚本 (GAS) - 创建 ContentService API 以提供来自 Google Drive 的 JSON 数据
【发布时间】:2012-08-15 14:49:11
【问题描述】:

仍在尝试找出在 Google IO 2012 上推出的所有新内容。关于 GAS 和 ContentService,您应该能够创建一个 API 来提供您的内容(来自 Google Drive)。一个简单的例子是这样的:

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;

}

然后从一个普通的网页,希望使用jQuery Ajax,你应该可以得到Json数据?

简单的 javascript 代码在普通(非 GAS)客户端上会是什么样子?

【问题讨论】:

    标签: jquery google-apps-script google-drive-api


    【解决方案1】:

    看看JSONP 看看它应该是什么样子

    另外,应该是output.setContent(JSON.stringify(jsonData));

    【讨论】:

    • 感谢 Cory,即使进行了更改,我的超级基本示例仍然无法正常工作。您介意发布一个包含 GAS 和 Client JS 的简单示例吗?目前我的客户端 JS 是: $.ajax({ url: url, crossDomain: true, dataType:'jsonp', cache: false, type: 'GET', success: function (data) { console.log(data); } })
    • 很遗憾,我无法在客户端方面为您提供真正的帮助。通过在浏览器中查看该 URL 的结果,可以轻松地测试应用程序脚本部分。
    猜你喜欢
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多