Migrating from SQL API to Fusion Tables v1

白昼怎懂夜的黑 提交于 2019-12-11 14:08:25

问题


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 this
var URLTable = encodeURI('SELECT id,COUNT() FROM TABLE_ID')
to this
var URLTable = encodeURI('SELECT COUNT() FROM TABLE_ID')



来源:https://stackoverflow.com/questions/11486633/migrating-from-sql-api-to-fusion-tables-v1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!