0

我有以下 Google Apps 脚本代码可将值发布到 Fusion 表:

function insertData(authToken){
  var sql="INSERT INTO 1558685(Constituency,Male Voters,Female Voters,Total Population) VALUES ('Langata',65000,5000,350000)";
  query = encodeURIComponent(sql); 
  var URL = "https://www.google.com/fusiontables/api/query/sql=" + query;
  var response = UrlFetchApp.fetch(URL,{method: "post",headers: {"Authorization": "GoogleLogin auth=" + authToken,"Content-Type": "text/html; charset=UTF-8",
                                                                 "Content-length": sql.length,}});

  Logger.log(response.getContentText());

}

每次运行此代码时,我都会收到以下错误: 属性提供的值无效:标头:内容长度(第 36 行)

我已尝试删除“内容长度”标头,但出现有关sql 参数不能为空的错误

4

1 回答 1

1

请尝试以下操作:

function insertData(authToken){
  var sql="INSERT INTO 1558685 (Constituency,'Male Voters','Female Voters','Total Population') VALUES ('Langata',65000,5000,350000)";
  var query = encodeURIComponent(sql); 
  var URL = "https://www.google.com/fusiontables/api/query";
  var response = UrlFetchApp.fetch(URL, { 
    method: "post",
    headers: { "Authorization": "GoogleLogin auth=" + authToken },
    payload: "sql=" + query // this send the query in the body of the request
  });

 Logger.log(response.getContentText());
}
于 2011-11-17T17:15:26.170 回答