I would like to write a small Google Chrome extension in which I use gooles fusion tables as a central data base.
Using existing tables and data (added via the GooleDoc-Webside) works quite fine (SELECT, SHOW TABLES, DESCRIBE) but if I try to do any changes (for this I need a "POST" request). I always get the following error: "Missing sql parameter." I have no Idea why this happens. I tried already alot (e.g. "create table test3(A:number,B:number)", insert .)
The code I wrote is the following:
function Fusion(readyCallback) {
var myObject = {
URL : "https://www.google.com/fusiontables/api/query",
authToken : null,
doGET : function(command,callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("get"
,this.URL+"?sql="+encodeURI(command)
,true);
xmlhttp.setRequestHeader("Authorization"
,"GoogleLogin auth=" + this.authToken);
xmlhttp.onreadystatechange = function() { callback(xmlhttp.responseText); }
xmlhttp.send();
},
doPOST : function(command,callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("post"
,this.URL
,true);
xmlhttp.setRequestHeader("Authorization"
,"GoogleLogin auth=" + this.authToken);
xmlhttp.onreadystatechange = function() { callback(xmlhttp.responseText); }
xmlhttp.send("sql="+encodeURI(command));
}
}
// client login authentification
var email = "XXX@gmail.com";
var password = "XXX";
var loginURL = "https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email="
+ encodeURI(email) + "&Passwd=" + encodeURIComponent(password)
+ "&service=fusiontables&Source=testing";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("get",loginURL,true);
xmlhttp.onreadystatechange = function() {
var tmp = xmlhttp.responseText;
tmp = tmp.slice(tmp.search("Auth=") + 5, tmp.length);
tmp = tmp.replace(/\n/g, "");
tmp = tmp.replace(/\r/g, "");
myObject.authToken = tmp;
console.log("authentifiaction token status: "+xmlhttp.statusText);
if (readyCallback) {
readyCallback();
}
};
xmlhttp.send();
return myObject;
}
If I for example try to do something like this
mf.doPOST("INSERT INTO 2664928(ID,Text,Number) VALUES (2,'Hallo',3)",mc)
or this
mf.doPOST("INSERT INTO 2664928(col4,col0,col1) VALUES (2,'Hallo',3)",mc)
with a table, described by this
column id,name,type
col4,ID,number
col0,Text,string
col1,Number,number
I keep getting this error (the same when I try to create a table)
Any suggestions? I am realy confused!