发布时的Google脚本错误

时间:2017-02-22 22:28:23

标签: php curl google-apps-script

我使用php将数据发布到google工作表,每次我发布正确添加到工作表上的数据,但我收到错误消息

  

We8d#39;很抱歉,发生了服务器错误。请稍等一下试试吧   试。

我的php curl邮政编码是:

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $gsurl);
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 $output = curl_exec($ch);
 $info = curl_getinfo($ch);
 curl_close($ch);

$res = json_decode($output, 1);

我的GS App脚本是:

var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service


function doGet(e){
  return handleResponse(e);
}

function doPost(e){
  return handleResponse(e);
}

function handleResponse(e) {
  var lock = LockService.getPublicLock();
  lock.waitLock(30000); 

  try {

    var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("key"));
    var sheet = doc.getSheetByName(SHEET_NAME);


    var headRow = e.parameter.header_row || 1;
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
    var nextRow = sheet.getLastRow()+1; 
    var row = []; 

    for (i in headers){
      if (headers[i] == "Timestamp"){ 
        row.push(new Date());
      } else { 
        row.push(e.parameter[headers[i]]);
      }
    }

    sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
    // return json success results
    return ContentService
          .createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
          .setMimeType(ContentService.MimeType.JSON);
  } catch(e){

    return ContentService
          .createTextOutput(JSON.stringify({"result":"error", "error": e}))
          .setMimeType(ContentService.MimeType.JSON);
  } finally { 
    lock.releaseLock();
  }
}

function setup() {
    var doc = SpreadsheetApp.getActiveSpreadsheet();
    SCRIPT_PROP.setProperty("key", doc.getId());
}

请帮帮我。

0 个答案:

没有答案