Archive

Posts Tagged ‘vb’

VB.net Add Calendar Entry Google API

April 11, 2012 Leave a comment

Adding a new calendar event to Google Calendar via the API is easier than I thought. Only a few lines of code to get a new calendar event setup and added. I did not do this with the “quick add” method, but that one looks even easier.

At the top:

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

I have this bit -o- code in a sub, called from a button click on my test app:

Dim newEvent As New EventEntry
Dim newatom As AtomEntry

Dim serv As New Google.GData.Calendar.CalendarService("GCal")
serv.setUserCredentials("you@email.com", "yourGPWD")
newEvent.Title.Text = "New Event Title"
newEvent.Content.Content = "This is the event description"
Dim newTime As New [When]()
newTime.StartTime = Convert.ToDateTime(DTSTB.text) 'getting date/time from textbox for testing
newTime.EndTime = DateAdd(DateInterval.Hour, 1, Convert.ToDateTime(TextBox3.Text)) 'add 1 hour for end
newEvent.Times.Add(newTime)

Dim uri As New Uri("https://www.google.com/calendar/feeds/default/private/full")
newatom = serv.Insert(uri, newEvent)

The “newatom” object as an Atomentry contains all of the details of the newly created event. I have to dig some more to find a good method for determining if the event was created correctly or not. Right now I’m looking at the URI for the event, making the assumption that if I get a URI back, the event was created properly.