here is an example of my code (partial) @tpakis:
Dim clientId As String : clientId = "9289.........apps.googleusercontent.com"
Dim clientSecret As String : clientSecret = "cJoy0s......-....-....."
Dim AuthorizationCode, AccessToken As String
Dim XmlParser As SaxParser
Dim hc As HttpClient
End Sub
Sub Activity_Create(FirstTime As Boolean)
tableID="1RA9Ca....."
...
...
Sub btnTrasmettiCodici_Click
If AuthorizationCode = "" Then
'show a WebView that will ask the user to give us access
Dim scope As String
scope = "https://www.googleapis.com/auth/fusiontables"
Dim wv As WebView
wv.Initialize("wv")
Activity.AddView(wv, 0, 0, 100%x, 100%y)
wv.LoadUrl("https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=" _
& clientId & "&redirect_uri=urn:ietf:wg
auth:2.0
ob&scope=" & scope)
' Button1.Enabled = False
Else If AccessToken = "" Then
GetAccessToken
Else
TrasmettiCodiciLetti
End If
' SalvaFileConsegne
' LeggiDatiConsegna
End Sub
Sub wv_PageFinished (Url As String)
If Url.StartsWith("https://accounts.google.com/o/oauth2/approval") Then
Dim wv As WebView
wv = Sender
Dim w As WebViewXtender
Dim result As String
result = w.getTitle(wv)
wv.RemoveView 'remove the WebView
If result.StartsWith("Success code") Then
AuthorizationCode = result.SubString("Success code=".Length)
GetAccessToken
Else
Log("Errore: " & result)
ToastMessageShow(result, True)
End If
End If
End Sub
Sub GetAccessToken
Dim postString As String
postString = "code=" & AuthorizationCode & "&client_id=" & clientId & "&client_secret=" & clientSecret _
& "&grant_type=authorization_code&redirect_uri=urn:ietf:wg
auth:2.0
ob"
HttpUtils.postString("GetAccessToken", "https://accounts.google.com/o/oauth2/token", postString)
ProgressDialogShow("Sending authentication request...")
End Sub
Sub JobDone (Job As String)
ProgressDialogHide
Select Job
Case "Insert"
url = HttpUtils.Tasks.Get(0)
If HttpUtils.IsSuccess(url) Then
ToastMessageShow("Dati trasmessi correttamente", True)
Else
ToastMessageShow("Errore trasmissione dati", True)
End If
Case "GetAccessToken"
Dim url As String
url = HttpUtils.Tasks.Get(0)
'Log(HttpUtils.GetString(url))
If HttpUtils.IsSuccess(url) Then
Dim Parser As JSONParser
Parser.Initialize(HttpUtils.GetString(url))
Dim m As Map
m = Parser.NextObject
AccessToken = m.Get("access_token")
'you may also want to get the refresh_token
TrasmettiCodiciLetti
Else
ToastMessageShow("Error getting access token", True)
' Button1.Enabled = True
End If
End Select
HttpUtils.Complete = False
End Sub
Sub TrasmettiCodiciLetti
Dim indx As Int
Dim Cursore As Cursor
Dim Lettura As TipoDatiConsegna
Dim QueryUrl As String
Dim CodiciInMemoria As Int
Cursore = CaricaCodiciLetti
CodiciInMemoria= Cursore.RowCount
For indx = CodiciInMemoria - 1 To 0 Step -1
Cursore.Position = indx
Lettura.Lat=Cursore.Getdouble("lat")
Lettura.Lon=Cursore.Getdouble("lon")
Lettura.DataeOra=Cursore.GetLong("data")
Lettura.Barcode=Cursore.GetString("Barcode")
QueryUrl=QueryInsert(tableID,Lettura.Barcode,Lettura.Lat,Lettura.Lon,Lettura.DataeOra)
req1.InitializePost2(QueryUrl.Replace(" ","+"),"".GetBytes("UTF8"))
hc.Execute(req1,indx+1)
QueryService.DeleteRow(Lettura.Barcode)
DelRowSV(SVCodiciLetti,indx, Cursore.GetString("Barcode"))
NumeroConsegne=NumeroConsegne-1
' PostQuery("Insert" & i, QueryInsert(tableID,Lettura.Barcode,Lettura.Lat,Lettura.Lon,Lettura.DataeOra))
Next
If CodiciInMemoria<2 Then
ToastMessageShow("Inviato " & CodiciInMemoria & " codice letto" , True)
Else
ToastMessageShow("Inviati " & CodiciInMemoria & " codici letti" , True)
End If
Cursore.Close
End Sub
Sub QueryInsert(TabID As String, Barcode As String, lat As Double, lon As Double, DataLettura As Long) As String
Dim Query As String
Dim QueryLink As String
Dim QuerySql As String
QueryLink = "https://www.google.com/fusiontables/api/query"
QuerySql="?sql=INSERT+INTO+"&TabID&"+(Barcode,GPS,Data)+VALUES+('" & Barcode & "','" _
& lat & "+" & lon & "','" & DateTime.Date(DataLettura) & "+" & DateTime.Time(DataLettura) & "')"
Query=QueryLink & QuerySql & "&access_token=" & AccessToken
Log(Query)
Return Query
End Sub
Sub PostQuery(job As String, QueryCommand As String)
HttpUtils.PostString(job, QueryCommand ,"")
'HttpUtils.Download("ContactList", ContactsListLink & "?access_token=" & AccessToken & "&v=3.0&max-results=100")
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim resultString As String
Result = Response.GetString("UTF8")
'Work with the result
' If Result = True Then QueryService.DeleteRow(
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log("Error connecting: " & Reason & " " & StatusCode)
If Response <> Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
End Sub