我想编写一个小的 Google Chrome 扩展,在其中我使用 gooles 融合表作为中央数据库。
使用现有的表和数据(通过 GooleDoc-Webside 添加)工作得很好(SELECT、SHOW TABLES、DESCRIBE),但如果我尝试进行任何更改(为此我需要一个“POST”请求)。我总是收到以下错误:“缺少 sql 参数。” 我不知道为什么会这样。我已经尝试了很多(例如“创建表test3(A:number,B:number)”,插入。)
我写的代码如下:
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;
}
例如,如果我尝试做这样的事情
mf.doPOST("INSERT INTO 2664928(ID,Text,Number) VALUES (2,'Hallo',3)",mc)
或这个
mf.doPOST("INSERT INTO 2664928(col4,col0,col1) VALUES (2,'Hallo',3)",mc)
用一张桌子,由这个描述
column id,name,type
col4,ID,number
col0,Text,string
col1,Number,number
我不断收到此错误(尝试创建表时相同)
有什么建议么?我真的很困惑!