0

在 SQL API 被弃用后搜索解决方案从 SQL API 迁移 https://www.google.com/fusiontables/api/query?sql=https://www.googleapis.com/fusiontables/v1/query?sql=喜欢这里

我有:

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.尝试更改jsonCallbackcallback- 没有帮助!

4

1 回答 1

1

最后!通过替换 jQuery 示例找到了纯粹而简单的解决方案。使用google-api-javascript-client
不要忘记添加到 head 标签中
<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')

于 2012-07-31T19:48:58.810 回答