Unable to set value for Content-length when using Fusion tables API and Google Apps Script
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());
}
精彩评论