Home > VB.net > Google Calendar API in VB.net (VS 2008) – Display Calendar Events

Google Calendar API in VB.net (VS 2008) – Display Calendar Events

I poked around the web for some samples on integrating Google Calendar into a VB.net 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("http://www.google.com/calendar/feeds/YOURGOOGLE 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: VB.net Tags: , , ,
  1. jules
    September 10, 2012 at 5:35 pm

    Dont know if you are still looking at this but it only retrieves 25 records/Entries max could you post how to get more than that please, for vb.net

    • September 10, 2012 at 6:16 pm

      sorry, work has dictated that I abandon Google for Exchange

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: