Welcome! Log In Create A New Profile

Advanced

WB12 - Google Calendar API's

Posted by Peter Holemans 
Peter Holemans
WB12 - Google Calendar API's
July 28, 2008 03:22PM
Hi,

For a web project (extranet) I want to integrate the Google Calendar features. Did any of you got this to work in WebDev? I'm able to include it in my webdev pages pretty easily, but now I want to post events (new appointments, updates, deletes) etc. from my webdev app as well to teh Google Calendars. If any of you has already done this, a fast track on how to get there and some sample code would be greatly appreciated?

Cheers,

Peter
Peter Holemans
Re: WB12 - Google Calendar API's
July 29, 2008 12:40AM
Getting closer but extremely slowly... I'm able to log on get an authentication code en proceed, but the first tryout of an add event times out using the WX httprequest() command. Also for update and deletion of calendar events I will need to be able to trigger http put and http delete requests as well aside from the standard http post requests. I searched even the french fora, but nothing on there regarding the Google Calendar http requests. This is a bit a drawback, on .net or even VB you can find tons of info and code samples on how to get this up and running...

So any suggestions would be greatly appreciated.

Cheers, Peter

Some code:
=============================
objGoogleCalendar est une classe
PUBLIC
	str_gCalLoginSID is string
	str_gCalLoginLSID is string
	str_gCalLoginAUTH is string
	str_gCalAccount is string = "default"
	str_gCalErrorLoginMessage is string
	str_gCalErrorAddMessage is string
	str_gCalErrorUpdateMessage is string
	str_gCalErrorDeleteMessage is string
PUBLIC
	GLOBAL
	CONSTANT
		URL_GOOGLE_LOGIN = "[www.google.com];
		URL_GOOGLE_LOGIN_PARAMS = "Email=%1&Passwd=%2&source=UniglobeUPM&service=cl"
		URL_GCAL_REQUEST = "[www.google.com];	//%1 = Account for which the calendar needs to be updated - Default for own calendar
		URL_GCAL_REQUEST_AGENT = "Mozilla/4.0 (compatible; MSIE 6.0; Winrdows NT 5.0)"
		URL_GCAL_REQUEST_AUTH_HEADER = "Authorization:GoogleLogin auth=%1"		//%1 = Received authorization key during login
		URL_GCAL_CONT_TYPE_ADD = "application/atom+xml"
		URL_GCAL_CONT_TYPE_MOD = " "
		URL_GCAL_CONT_TYPE_DEL = " " 
		XML_GCAL_ADD_EVENT = "<entry xmlns='[www.w3.org]; "+...		// POST HTTP STATEMENT
		"xmlns:gd='[schemas.google.com]...
		"<category scheme='[schemas.google.com]...
		"term='[schemas.google.com]...
		"<title type='text'>%1</title>"+...											//%1 = Title or subject
		"<content type='text'>%2</content>"+...									//%2 = Body
		"<gd:where valueString='%3'></gd:where>"+...								//%3 = Location
		"<gd:when startTime='%4T%5.000Z'"+...									//%4 = Startdate yyyy-mm-dd	%5 = Starttime HH:MMconfused smileyS:CCC
		"endTime='%6T%7.000Z'>"+...											//%6 = Enddate yyyy-mm-dd	%7 = Endtime HH:MMconfused smileyS:CCC
		"<gd:reminder days='%8'/></gd:when>"+...									//%8 = Reminder days
		"<gd:transparency"+...
		"value='[schemas.google.com]...
		"</gd:transparency>"+...
		"<gd:eventStatus"+...
		"value='[schemas.google.com]...
		"</gd:eventStatus>"+...
		"</entry>"
		XML_GCAL_UPDATE_EVENT =   "<entry xmlns='[www.w3.org]; "+...	// PUT HTTP STATEMENT
		"xmlns:gd='[schemas.google.com]; "+...
		"xmlns:gCal='[schemas.google.com]...
		"<id>[www.google.com]...			//%1 = User for which the calendar needs to be updated %2 = Message ID
		"<category scheme='[schemas.google.com]...
		"term='[schemas.google.com]...
		"<title type='text'>%3</title>"+...											//%3 = Title or subject
		"<content type='text'>%4</content>"+...									//%4 = Body
		"<gd:where valueString='%5'></gd:where>"+...								//%5 = Location
		"<gd:when startTime='%6T%7.000Z'"+...									//%6 = Startdate yyyy-mm-dd	%7 = Starttime HH:MMconfused smileyS:CCC
		"endTime='%8T%9.000Z'>"+...											//%8 = Enddate yyyy-mm-dd	%9 = Endtime HH:MMconfused smileyS:CCC
		"<gd:reminder days='%10'/></gd:when>"+...									//%10 = Reminder days
		"<gd:transparency"+...
		"value='[schemas.google.com]...
		"</gd:transparency>"+...
		"<gd:eventStatus"+...
		"value='[schemas.google.com]...
		"</gd:eventStatus>"+...	
		"</entry>"
		XML_GCAL_DELETE_EVENT =   "<entry xmlns='[www.w3.org]; "+...	// DELETE HTTP STATEMENT
		"xmlns:gd='[schemas.google.com]; "+...
		"xmlns:gCal='[schemas.google.com]...
		"<id>[www.google.com]...			//%1 = User for which the calendar needs to be updated %2 = Message ID
		"<category scheme='[schemas.google.com]...
		"term='[schemas.google.com]...
		"</entry>"
	FIN
FIN
=============================
FUNCTION gCal_Login() //WORKS FINE
:str_gCalErrorLoginMessage = ""
IF HTTPRequête(::URL_GOOGLE_LOGIN+"?"+StringBuild(::URL_GOOGLE_LOGIN_PARAMS,objsession::str_gCalendarSharedUser,objSession::str_gCalendarSharedPassword),"","","","Content-Type:application/x-www-form-urlencoded") THEN
	//Get SID, LSID and AUTH
	lstr_gCalReply is string = HTMLVersTexte(HTTPDonneRésultat(HTTPRésultat))
	//Check for failed authentication ("Error=BadAuthentication<10>")
	IF StringCount(lstr_gCalReply,"ERROR",SansCasse) <= 0  THEN
		:str_gCalLoginSID = ExtractString(lstr_gCalReply,2,"SID=",DepuisDébut)
		:str_gCalLoginLSID = ExtractString(lstr_gCalReply,2,"LSID=",DepuisDébut)
		:str_gCalLoginAUTH = ExtractString(lstr_gCalReply,2,"Auth=",DepuisDébut)
		IF NOT :str_gCalLoginAUTH ~= "" AND :str_gCalLoginAUTH <> EOT THEN
			RESULT True
		ELSE
			:str_gCalErrorLoginMessage = StringBuild("Fout: De authenticatiesleutel voor Google account %1 kon niet worden opgehaald.",objSession::str_gCalendarSharedUser)
			RESULT False
		END
	ELSE
		:str_gCalErrorLoginMessage = StringBuild("Fout: De Google service vermelde onderstaande fout bij het aanmelden van %1 :",objSession::str_gCalendarSharedUser)+CR+lstr_gCalReply
		RESULT False
	END
ELSE
	:str_gCalErrorLoginMessage = StringBuild("Fout: De aanmelding aan de Uniglobe Belux Google account(%1)  is mislukt.",objSession::str_gCalendarSharedUser)
	RESULT False
END
=============================
FUNCTION gCal_AddEvent(lint_CoworkerID is int = 0)
//Do logic
:str_gCalErrorAddMessage = ""
IF :gCal_Login() THEN
	IF lint_CoworkerID > 0 THEN
		//Get user account credentials
		 HReadSeekFirst(Coworker,CoworkerID,lint_CoworkerID)
		 IF HFound(Coworker) THEN
		 	IF NOT Coworker.gCalendarPrivateURL ~= "" THEN
				//Get account name out of private calendar url
				lstr_TempString is string = ExtractString(Lower(Coworker.gCalendarPrivateURL),2,"src=",DepuisDébut)
				lint_TempPosition is int = Position(lstr_TempString,"&",1,DepuisDébut+SansCasse)
				IF lint_TempPosition > 0 THEN lstr_TempString = Left(lstr_TempString,lint_TempPosition-1)
				:str_gCalAccount = lstr_TempString
				IF :str_gCalAccount ~= "" OR :str_gCalAccount = EOT THEN
					:str_gCalErrorAddMessage = "Fout: De voor de opgegeven medewerker Google Calendar privélink bevat geen gebruikersgegevens en is wellicht ongeldig."+CR+...
					" Gelieve deze bij te werken naar een geldige link bij de module medewerkerbeheer."+CR+CR+"(Link bevat geen 'src=' element)"
					RESULT False
				END
		 	ELSE
				:str_gCalErrorAddMessage = "Fout: Voor de opgegeven medewerker is er geen Google Calendar privélink opgegeven. Gelieve deze eerst toe  te voegen bij het beheer van de medewerkers."
				RESULT False
		 	END
		 ELSE
			:str_gCalErrorAddMessage = "Fout: De opgegeven medewerker waarvoor deze afspraak dient et worden vatsgelegd, kon niet worden gevonden."
			RESULT False
		 END
	ELSE
		//Enter event into current user account
		:str_gCalAccount = "default"
	END
	//Set URL
	lstr_gCalendarURL is string = StringBuild(::URL_GCAL_REQUEST,:str_gCalAccount)
	lstr_GCalendarAUTHHeader is string = StringBuild(::URL_GCAL_REQUEST_AUTH_HEADER,:str_gCalLoginAUTH)
	//Build XML Message
	//%1 = Title or subject
	//%2 = Body
	//%3 = Location
	//%4 = Startdate yyyy-mm-dd	%5 = Starttime HH:MMconfused smileyS:CCC
	//%6 = Enddate yyyy-mm-dd	%7 = Endtime HH:MMconfused smileyS:CCC
	//%8 = Reminder days
	lstr_XMLBody is string = StringBuild(:angry smileyML_GCAL_ADD_EVENT, TextToXML(MeetingRequest.Subject), TextToXML(MeetingRequest.Notes), TextToXML(MeetingRequest.Location), ...
	TextToXML(DateToString(MeetingRequest.MeetingDate,"AAAA-MM-JJ")),TextToXML(TimeToString(MeetingRequest.StartTime,"HH:MMconfused smileyS")), ...
	TextToXML(DateToString(MeetingRequest.MeetingDate,"AAAA-MM-JJ")),TextToXML(TimeToString(MeetingRequest.EndTime,"HH:MMconfused smileyS")),"1")
	//Send HTTP Request
	IF HTTPRequête(lstr_gCalendarURL,::URL_GCAL_REQUEST_AGENT,lstr_GCalendarAUTHHeader,lstr_XMLBody,::URL_GCAL_CONT_TYPE_ADD) THEN
		
		//===> THE ABOVE REQUEST TIMES OUT <===
		
		//Get reply
		lstr_gCalReply is string = HTMLVersTexte(HTTPDonneRésultat(HTTPRésultat))
		RESULT True
	ELSE
		:str_gCalErrorAddMessage = "Fout: De HTTP aanvraag voor de toevoeging van de meeeting is mislukt."
		RESULT False	
	END
ELSE
	:str_gCalErrorAddMessage = :str_gCalErrorLoginMessage
	RESULT False
END
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: