开发者

Unable to set value for Content-length when using Fusion tables API and Google Apps Script

开发者 https://www.devze.com 2023-04-06 15:23 出处:网络
I have the following Google Apps Script code to POST values to a Fusion table: function insertData(authToken){

I have the following Google Apps Script code to POST values to a Fusion table:

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=" + au开发者_如何学GothToken,"Content-Type": "text/html; charset=UTF-8",
                                                                 "Content-length": sql.length,}});

  Logger.log(response.getContentText());

}

Every time I run this code I get the following error: Attribute provided with invalid value: Header:Content-length (line 36)

I've tried removing the 'Content-length' header but I get an error about sql parameter cannot be empty


try the following instead:

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());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消