Archive

Posts Tagged ‘Google’

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.

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

April 6, 2012 2 comments

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
next

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: , , ,