无法使用Apps脚本(Webhooks)解析x-www-form-urlencoded

问题描述 投票:0回答:1

我正在尝试使用Apps脚本(作为Webapp)在Gsheet中获取POST请求!它适用于JavaScript主体POST类型,但是当我尝试使用x-www-form-urlencoded时出现错误。

function doPost(e) {

//Return if null
  if( e == undefined ) {
      console.log("no data");
      return HtmlService.createHtmlOutput("need data");
    }

//Parse the JSON data

  var event = JSON.parse(e.postData.contents);
  var data = event.data;


//Get the last row without data

  var sheet = SpreadsheetApp.getActiveSheet();
  var lastRow = Math.max(sheet.getLastRow(),1);
  sheet.insertRowAfter(lastRow);

//Get current timestamp

  var timestamp = new Date();

//Insert the data into the sheet

  sheet.getRange(lastRow + 1, 1).setValue(event.bt_signature);
  sheet.getRange(lastRow + 1, 2).setValue(data.bt_payload);
  SpreadsheetApp.flush();

  return HtmlService.createHtmlOutput("post request received");}

谢谢!

javascript google-apps-script
1个回答
0
投票

对于x-www-form-urlencoded内容,POST数据存储在事件对象的parameterparameters属性中。参见documentation

© www.soinside.com 2019 - 2024. All rights reserved.