问题
After SQL API was deprecated searching solution to migrate from SQL API
https://www.google.com/fusiontables/api/query?sql=
to https://www.googleapis.com/fusiontables/v1/query?sql=
like here
I got:
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 )
}
I need:
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 )
}
Looks like it's not so easy to migrate from SQL API
to /fusiontables/v1/
for me.
EDIT:
1. Try to change the jsonCallback
to callback
- not helped!
回答1:
Finaly! Found pure and simple solution by replacing jQuery examp. with google-api-javascript-client
Don't forget to add into head tag<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)
}
}
EDIT:
Or simply just like in first example above change thisvar URLTable = encodeURI('SELECT id,COUNT() FROM TABLE_ID')
to thisvar URLTable = encodeURI('SELECT COUNT() FROM TABLE_ID')
来源:https://stackoverflow.com/questions/11486633/migrating-from-sql-api-to-fusion-tables-v1