Hi chaps,
Messing around with Google Calendar and the HTTP.DLL.
I have managed to write code to get an authentication token from Google, now I just need to add my token to an Authentication header in my next request to their server.
How would I go about doing this? The headers function appears to be read-only and putting the token in the ContentType field fails as well.
Here's the code so far:
Thanks in advance,
Rich
Messing around with Google Calendar and the HTTP.DLL.
I have managed to write code to get an authentication token from Google, now I just need to add my token to an Authentication header in my next request to their server.
How would I go about doing this? The headers function appears to be read-only and putting the token in the ContentType field fails as well.
Here's the code so far:
B4X:
Sub Globals
'Declare the global variables here.
End Sub
Sub App_Start
Form1.Show
End Sub
Sub Button1_Click
request.New1("https://www.google.com/accounts/ClientLogin")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
stream.New1(request.GetStream,True)
name="Email=" & googemail.Text & "&Passwd=" & googpassword.Text & "&source=obstudios-studiomanger-1&service=cl"
stream.WriteBytes(stream.StringToBytes(name))
response.New1
request.GetAsyncResponse
End Sub
Sub request_Response
If request.ResponseCode = 200 Then
response.Value = request.AsyncResponse
response.GetAsyncString
Else
Msgbox(request.ErrorMessage)
End If
End Sub
Sub response_Stream
servrep.Text = response.AsyncString
'Get the Authorisation code
locauth = StrIndexOf(response.AsyncString,"Auth=",0)
authcode.Text = SubString(response.AsyncString,locauth+5,StrLength(response.AsyncString) - locauth+5)
response.Close
'Now connect up to Google Calendar
request2.New1("http://www.google.com/calendar/feeds/default/private/full")
request2.Method = "POST"
'request2.Headers = "Authorization: GoogleLogin auth=" & authcode.Text <-- In an ideal world this would work
request2.ContentType = "application/atom+xml;"
'Construct the XML
EventCode = "<entry xmlns:gd='http://schemas.google.com/g/2005'>" & CRLF & _
"<category scheme='http://schemas.google.com/g/2005#kind'" & CRLF & _
"term='http://schemas.google.com/g/2005#event'/>" & CRLF & _
"<published>2005-01-18T21:00:00Z</published>" & CRLF & _
"<updated>2006-01-01T00:00:00Z</updated>" & CRLF & _
"<title>Work Schedule</title>" & CRLF & _
"<content>No description</content>" & CRLF & _
"<author>" & CRLF & _
"<name>" & googname.Text & "</name>" & CRLF & _
"<email>" & googemail.Text & "</email>" & CRLF & _
"</author>" & CRLF & _
"<gd:when startTime='" & googdate.Text & "T" & googstart.Text & ":00Z'" & CRLF & _
"endTime='" & googdate.Text & "T" & googend.Text & ":00Z'></gd:when>" & CRLF & _
"<gd:where valueString='Studio'/>" & CRLF & _
"<gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>" & CRLF & _
"<gd:visibility value='http://schemas.google.com/g/2005#event.public'/>" & CRLF & _
"<gd:transparency value='http://schemas.google.com/g/2005'event.transparent'/>" & CRLF & _
"</entry>"
stream2.New1(request2.GetStream,True)
stream2.WriteBytes(stream2.StringToBytes(eventcode))
response2.New1
request2.GetAsyncResponse
End Sub
Sub request2_Response
If request2.ResponseCode = 200 Then
response2.Value = request2.AsyncResponse
response2.GetAsyncString
Else
Msgbox(request2.ErrorMessage)
End If
End Sub
Sub response2_Stream
Msgbox(response.AsyncString)
End Sub
Thanks in advance,
Rich