Google Fusion Tables

shrz

Member
Licensed User
Longtime User
Is it possible to connect to Google fusion tables to download a csv via an app created by b4a? Or is there another way i can allow users access to my csv file without any additional setup other than installing the app?
 

shrz

Member
Licensed User
Longtime User
the fusion table is a csv file that i can use sql commands to query via rest commands, but not sure how to do this with b4a, I have the below example that where I am trying to display the table headings but i get an error with httputilservice req.InitializeGet(link)



Sub Globals
Dim b4a As string
Dim label1 As Label
b4a="https://www.google.com/fusiontables/api/query?sql=DESCRIBE 1066695"
End Sub

Sub Activity_Create (FirstTime As Boolean)

activity.LoadLayout("f")
HttpUtils.CallbackActivity = "Main" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.Download("Job1", b4a)
End Sub

Sub JobDone (Job As String)
Dim s As String
If HttpUtils.IsSuccess(b4a) Then
label1.Text = HttpUtils.GetString(b4a)
End If
End Sub
 
Upvote 0

shrz

Member
Licensed User
Longtime User
Program paused at line req.initializeget(link)

The debugger says illegal character in query at index 58,
 
Upvote 0

shrz

Member
Licensed User
Longtime User
that allowed the url to be loaded although cannot access the file as i need to implement a login even though the file is public, the example code google advise to use is:

POST /accounts/ClientLogin HTTP/1.0
Content-type: application/x-www-form-urlencoded

accountType=GOOGLE &[email protected]&Passwd=north23AZ&service=fusiontables&
source=TheDataStewards-DataSyncr-1.05

but without any vb examples i just dont have the know how to use or implement this...

Will try looking into using google docs
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is a POST request. You can use HttpUtils.PostString to post this string.
You can set the content type header by modifying HttpUtilsService.ProcessNextTask:
B4X:
    If Post Then
        If PostInputStream.IsInitialized Then
            req.InitializePost(link, PostInputStream, PostLength)
        Else
            req.InitializePost2(link, PostBytes)
        End If
        req.SetContentType(...) '<----
    Else
 
Upvote 0

salvatore75

Member
Licensed User
Longtime User
I need to access the table of fusion google to update a table or insert new rows. I need an example of accessing the OAuth library or in any other way. Erel Can you help me?
Thank you! Congratulations for B4A
 
Upvote 0

salvatore75

Member
Licensed User
Longtime User

thanks, I saw the example, but I do not understand how to enter information "accountType"

from https://developers.google.com/fusion...Authentication ....

POST /accounts/ClientLogin HTTP/1.0
Content-type: application/x-www-form-urlencoded

accountType=GOOGLE&Email;[email protected]&Passwd;=north23AZ&service;=fusiontables&source;=TheDataStewards-DataSyncr-1.05

the method "accountType" does not exist in req. in the example:

If Post Then
If PostInputStream.IsInitialized Then
req.InitializePost(link, PostInputStream, PostLength)
Else
req.InitializePost2(link, PostBytes)
End If
req.SetContentType(...) '<----
Else
....

Can help me ??

Thanks,
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This information is the POST data. It should be something like:
B4X:
Dim su As StringUtils
Dim bytes() As Byte
bytes = su.EncodeUrl("accountType=GOOGLE&Email;[email protected]&Passwd; =north23AZ&service;=fusiontables&source;=TheDataSt ewards-DataSyncr-1.05", "UTF8").GetBytes("UTF8")
req.InitializePost2(link, bytes)
 
Upvote 0

salvatore75

Member
Licensed User
Longtime User
I'm going crazy for a http post to Google Fusion tables !!!!!!!!
I modified the example gmailcontacts OAuth 2.0 / Google web services tutorial for accessing google fusion tables. I get the access_token but the on HttpUtils.PostByte i get in sub hc_ResponsError StatusCode = 400 & Reason = "parse error near access_token" !!!

Help me I'm crazy, I tried in a thousand ways!

here the code:

Dim su As StringUtils
Dim bytes() As Byte
Dim sdata As String
Dim GoogleFusionPath As String
Dim query, auth, tail As String

GoogleFusionPath="https://www.google.com/fusiontables/api/query"
query="INSERT INTO 842604 (Barcode, GPS, Data) VALUES ('22222222', '10.1 11.1', '28/01/2012')"

auth="&access_token="& AccessToken
tail = "&jsonCallback=?"

sdata = "sql=" & su.EncodeUrl(query & auth & tail ,"UTF8")
bytes=sdata.GetBytes("UTF8")

HttpUtils.PostBytes("INSERT",GoogleFusionPath,bytes)
 
Upvote 0

salvatore75

Member
Licensed User
Longtime User
Thanks, but I modified the code as suggested by thedesolatesoul:

Dim su As StringUtils
Dim bytes() As Byte
Dim sdata As String
Dim GoogleFusionPath As String
Dim query, auth, tail As String

GoogleFusionPath="https://www.google.com/fusiontables/api/query?"
query="sql=INSERT INTO 842604 (Barcode, GPS, Data) VALUES ('22222222', '10.1 11.1', '28/01/2012')"

auth="&access_token="& AccessToken
tail = "&jsonCallback=?"

sdata = su.EncodeUrl(query & auth & tail ,"UTF8")
bytes=sdata.GetBytes("UTF8")

HttpUtils.PostBytes("INSERT",GoogleFusionPath,bytes)

I also tried GoogleFusionPath="https://www.google.com/fusiontables/api/query"

but does not work!

On HttpUtils.PostByte i get in sub hc_ResponsError StatusCode = 400 & Reason = "the 'sql' parameter cannot be empty" !!!
 
Upvote 0

salvatore75

Member
Licensed User
Longtime User
Ok this is the log(sdata) [with query="sql=INSERT.... and sdata=su.EncodeUrl(query & auth & tail ,"UTF8")]

"sql%3DINSERT+INTO+842604+%28Barcode%2C+GPS%2C+Data%29+VALUES+%28%2722222222%27%2C+%2710.1+11.1%27%2C+%2728%2F01%2F2012%27%29%26access_token%3Dya29.AHES6ZRN2mYRZiNcd3aKtDiQ8LI7Pm6Ztwk_27Tvr1x1t0c%26jsonCallback%3D%3F"

Thanks
 
Last edited:
Upvote 0

salvatore75

Member
Licensed User
Longtime User
ok !! In this case, On HttpUtils.PostByte i get in sub hc_ResponsError StatusCode = 400 & Reason = "the 'sql' parameter cannot be empty" !!!
 
Upvote 0
Top