不推荐使用SQL API后,搜索解决方案以从SQL API迁移
https://www.google.com/fusiontables/api/query?sql=
至https://www.googleapis.com/fusiontables/v1/query?sql=
,如here
我得到了:
var URLHead = 'https://www.google.com/fusiontables/api/query?sql='
var URLTable = encodeURI('SELECT id,COUNT() FROM TABLE_ID')
var URLTail = '&access_token='+ TOKEN +'&jsonCallback=?'
var queryURL = URLHead + URLTable + URLTail
var jqxhr = $.get(queryURL, myFT.TABLE, "jsonp")
this.myFT.TABLE = function (DATA) {
var counter = parseInt(DATA.table.rows[0].toString().substr(1))
alert(counter )
}
我需要:
var URLHead = 'https://www.googleapis.com/fusiontables/v1/query?sql='
var URLTable = encodeURI('SELECT id,COUNT() FROM TABLE_ID')
var URLTail = '&access_token='+ TOKEN +'&jsonCallback=?'
var queryURL = URLHead + URLTable + URLTail
var jqxhr = $.get(queryURL, myFT.TABLE, "jsonp")
this.myFT.TABLE = function (DATA) {
var counter = parseInt(DATA.table.rows[0].toString().substr(1))
alert(counter )
}
对我而言,从SQL API
迁移到/fusiontables/v1/
似乎并不那么容易。
修改
1.尝试将jsonCallback
更改为callback
- 没有帮助!
答案 0 :(得分:1)
Finaly!通过替换jQuery示例找到纯粹而简单的解决方案。与google-api-javascript-client
不要忘记添加到头标签中<script src="https://apis.google.com/js/client.js?onload=load"></script>
myTable1 = new FT('table1_id')
myTable1.run('SELECT * FROM ', myTable1, ' ORDER BY id ASC ')
function FT(table_id)
{
this.counter = 0
this.table = table_id
//
gapi.client.setApiKey('Api_Key')
//
this.run = function (q, cls, order)
{
gapi.client.load('fusiontables', 'v1', function(){
var request = gapi.client.fusiontables.query.sqlGet({'sql': q + cls.table + order});
request.execute(function(DATA){cls.exec(DATA)});
});
}
//
this.exec = function (DATA)
{
alert(DATA.result.rows.length)
}
}
修改强>
或者就像上面的第一个例子中那样改变这个
var URLTable = encodeURI('SELECT id,COUNT() FROM TABLE_ID')
到这个
var URLTable = encodeURI('SELECT COUNT() FROM TABLE_ID')