Posts Tagged ‘Google Calendar API’

Google Calendar API in (VS 2008) – Display Calendar Events

April 6, 2012 2 comments

I poked around the web for some samples on integrating Google Calendar into a app but didn’t find much more than bits n pieces. So I’ve started writing my own.
To start, all I wanted to do was extract calendar events for a given date range. I then take the title, startTime, endTime and ‘description’ and plop em into a listbox.

The first thing to do is make sure you have the Google API installed.

Then in your Studio project, add three references:

  • Google Data API Calendar
  • Google Data API Core
  • Google Data API Extensions

Now at the top of your code:

Imports Google.GData.Calendar
Imports Google.GData.Extensions
Imports Google.GData.Client

Now you can begin building the connection to Google. I have this setup in a sub right now but you could put it in the Form_load event:
Dim srvce As New Google.GData.Calendar.CalendarService("GCal")
Dim query As New FeedQuery
Dim entr As EventEntry
query.Uri = New Uri(" CAL ACCOUNT/private/full")
query.StartDate = "4/5/2012 8:00"      'optional but recommended so you don't get every single event, ever
query.EndDate = "4/5/2012 22:00"      'optional
query.ExtraParameters = "orderby=starttime&sortorder=ascending"   'optional but nice to have the events in order by date/time

Make sure you use your Google Calendar account’s email and password:

srvce.setUserCredentials("YOUR EMAIL","YOUR GOOGLE Cal PWD")
dim calfeed as atomfeed
calfeed = srvce.Query(query)
for each entr in calfeed.Entries

'  entr.Title.Text  has the title of the calendar event
' entr.Times.item(0).StartTime has the starting time of the event
'  entr.times.item(0).EndTime has the ending time of the event
' entr.Content.Content.ToString has the long description of the event

That’s all there really is to it. As I get a sample written for creating a new Event on a Calendar, I will post it. What I am currently doing is populating a gridview control that shows 8am to 10pm in one hour blocks. This will be used for scheduling Project Rooms. In the gridview, if you double click an open time slot, you are prompted if you would like to make a reservation.

Categories: Tags: , , ,