【问题标题】:Google apps script "ExecutionResponse" object does not contain "result"谷歌应用脚​​本“ExecutionResponse”对象不包含“结果”
【发布时间】:2015-10-28 00:06:38
【问题描述】:

我正在使用Google Scripts REST API 调用脚本。文档说“如果脚本函数成功返回,[响应] 字段将包含一个 ExecutionResponse 对象,函数的返回值作为对象的结果字段。”

但是,当响应返回时,它似乎不包含结果字段。我只是得到这个:

{
  "name": "CleanCSV",
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.apps.script.v1.ExecutionResponse"
  }
}

这是调用 API 调用的代码:

function callScript(SCRIPT_ID, SHEET_ID, token) {

        var xhr = new XMLHttpRequest();
        xhr.open("POST", 'https://script.googleapis.com/v1/scripts/' + SCRIPT_ID + ':run', true);
        xhr.setRequestHeader('Authorization', 'Bearer ' + token);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onload = function() {
            console.log(xhr.response); //this is what I pasted above
        };
        xhr.onerror = function() {
            console.log("D'Oh! That didn't work. Please try again");
        };
        var body = {};
        body.function = 'CleanCSV';
        body.parameters = [SHEET_ID];
        xhr.send(JSON.stringify(body));
};

Google 脚本文件非常简单。

function CleanCSV(sid) {

    //identify the sheet
    var ss = SpreadsheetApp.openById(sid);
    var sheet = ss.getSheets()[0];

   //...
   //do some stuff to the sheet
   //...

   return "hi there"; 
   //in reality, this will return some data
}

【问题讨论】:

  • 你确定你发布了最新的代码吗?
  • 嗯,这很尴尬。我在发布对话框中点击了“更新”,但似乎我需要将脚本发布为新版本。如果您想将其写为答案而不是评论,我会将其标记为已接受。

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


【解决方案1】:

可能您尚未保存代码的新版本或未使用该最新版本发布脚本。

https://developers.google.com/apps-script/guides/web#deploying_a_script_as_a_web_app

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多