简体   繁体   English

Apps Script API不会将数据粘贴到Google表格中

[英]Apps Script API not pasting data into Google Sheets

I'm trying to execute the function by calling it from my Chrome Extension. 我正试图通过Chrome扩展程序调用它来执行该功能。 I can see in my "My Executions" that the chrome extension called the function, but it's not pasting data into Google Sheets. 我可以在我的“我的执行”中看到chrome扩展称为函数,但它没有将数据粘贴到Google表格中。

  • When I try to run that function from the Script Editor directly it's working. 当我尝试直接从脚本编辑器运行该功能时,它正在工作。

Function Call from Chrome Extension 来自Chrome扩展程序的功能调用

post({ 'url': 'https://script.googleapis.com/v1/scripts/' + SCRIPT_ID + ':run',
  'callback': executionAPIResponse,
  'token': token,
  'request': {
    'function': 'setData',
    'parameters': { 'data': JSON.parse(exec_data.value) },
  }
});

Script Editor Code 脚本编辑器代码

function setData(parameters) {  
  try {
    var doc = SpreadsheetApp.openById(DOC_ID);
    var sheet = doc.getSheets()[0];
    var data = parameters.data;
    sheet.getRange(1, 1, data.length, data[0].length).setValues(data);
    return {"status":"ok", 'doc':doc.getUrl()};
  } catch(e){
    // if error return this
    Logger.log(e);
    return {"status": JSON.stringify(e)};
  }
}

I deployed the Apps Script project as "API Executable." 我将Apps脚本项目部署为“API可执行文件”。 I am wondering, is there something wrong with the way I deployed the app in Script Editor? 我想知道,我在脚本编辑器中部署应用程序的方式有问题吗?

getActiveSpreadsheet() only works on scripts projects bounded to a spreadsheet and only to access the the spreadshet that contains the script project. getActiveSpreadsheet()仅适用于绑定到电子表格的脚本项目,并且只能访问包含脚本项目的spreadshet。

Instead of using the above method use openByUrl(url) or openById(id) 而不是使用上面的方法使用openByUrl(url)openById(id)

I found the mistake i was making. 我发现了我犯的错误。 Actually the code was correct but while deploying as API Executable you have to always change the version to new one when you made changes to your code 实际上代码是正确的,但在部署为API Executable时,您必须始终在更改代码时将版本更改为新版本

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

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