Android Question How do I query a Google Fusion Table for data?

SteveJG

New Member
Licensed User
I can query this Google Fusion table ( at https://www.google.com/fusiontables/DataSource?docid=1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4 abd which is a publicGoogle demo table) using a Windows browser with the following url:

https://www.googleapis.com/fusiontables/v1/query?sql=SELECT ROWID, Product, Inventory FROM 1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4&key= use your key here



The url is a link to a public Google Fusion table. Do it and the query results in a JSON:


{
"kind": "fusiontables#sqlresponse",
"columns": [
"rowid",
"Product",
"Inventory"
],
"rows": [
[
"2",
"Amber Bead",
"1251500558"
],
[
"3",
"Black Shoes",
"356"
],
[
"4",
"White Shoes",
"100"
]
]
}


How do I do query a Fusion table to request data in B4A? Two routes seem possible; one method using http and another using a WebView with the WebExtras B4A library. I tried both, unsuccessfully and after several hours figured I better ask. The B4A http tutorials posted are either code snippets or complicated tutorials like the B4J FlickrViewer . These examples probably are great for experienced B4A users; my C++ and Delphi Windows experience is not helping me.


To use http, I understand I need to use httpUtils2 or the newer ... and use the httpUtils2 as a service;
to use JSON; perhaps use the WebViewer with the Windows url then parse the JSON result screen?

Is a simple example possible? I want to do a query of data in the 1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4 table using a SQL statement and then post the result. Just a simple message box showing that the number of black shoes is 356.

For those unfamiliar with Google Fusion tables, the key in the query string ( &key= ) is the authorization code provided by Google (users need to use their Google account and sign up to use a fusion table . Users get a reasonable number of access for free).

I can write a Windows program to do this query in C++ and Pascal. Is this 'simple' SQL query complicated in B4A ?

An example showing how to do this, a link etc. to get me started with the B4A methodology would be appreciated, even just the equivalent code to the SELECT statement (SELECT+ ROWID+Product+Inventory FROM STATEMENT . might all I need to make
progress.

Thank you.

--Steve
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is very simple to download resources with HttpUtils2.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim j As HttpJob
   j.Initialize("j", Me)
   j.Download("https://www.googleapis.com/fusiontables/v1/query?sql=SELECT+ROWID%2C+Product%2C+Inventory+FROM+1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4&key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ")
End Sub

Sub JobDone(j As HttpJob)
   If j.Success Then
     Log(j.GetString)
   Else
     Log(j.ErrorMessage)
   End If
   j.Release
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…