Tuesday, September 9, 2008

Google Calendar Service hosts a Gig Guide

Google Data APIs allow your client applications to interact with Google services such as Picassa Web Albums, Blogger Data and Calendar Data.

The .NET version of the API can be downloaded from here.

When Yarra Community Music Network wanted a Gig Guide on their site, I provided it by

  • using the Google Calendar service to maintain a list of events via a browser and
  • accessing this from the WEB application using Google.GData.Calander namespace in the API (see code snippet below)


Everything worked well on the local development site, but when it was loaded to the GoDaddy virtual WEB hosting, the page failed with a message like:

“System.Security.SecurityException: That assembly does not allow partially trusted callers”

This was finally overcome by using the Google API that was generated using “Allowing Partially Trusted Callers”.

It is in the “\Program Files\Google\Google Data API SDK\Redist\ASP.NET” folder

You must use the 1.2.2 (or later) version of the API. Earlier versions do not work.

(and explanation of sorts is in the README.TXT file)


Those assemblies here are identical to the assemblies in the Release directory, with the exception of being marked as PartiallyTrusted. If you
do not know what this means, or what the potential implications are for your website, refer to MSDN and search for


to get the information you need to use this correctly.

Note, while we believe that the Google Data assemblies follow security protocol, they do allow to call other websites directly, and hence
it is up to you, the developer of the website, to make that final judgement call. The assemblies in this directory are provide as is, and
just as a matter of convienience, as it is easy enough to recompile the code yourself.

A preliminary code snippet

With query
.Uri = New Uri("http://www.google.com/calendar/feeds/default/private/full")
.StartTime = Now.AddDays(-28) ' Set the date range
.EndTime = Now.AddMonths(6)
End With
Dim feed As EventFeed

With service
.setUserCredentials("me", "secret") ' *** you know what to do
feed = .Query(query)
End With
Dim dt As New DataTable ' store the results in a table for sorting
With dt.Columns
.Add("Start", Type.GetType("System.DateTime"))
.Add("End", Type.GetType("System.DateTime"))
End With
While feed.Entries.Count > 0
For Each entry As EventEntry In feed.Entries
With entry
For Each w As Object In .Times
If .Status.Value.Equals(EventEntry.EventStatus.CONFIRMED_VALUE.ToString) Then
' Only process confirmed events (in case a date in a repeating event has been deleted - say because of holidays)
Dim dr As DataRow = dt.NewRow
dr!Title = .Title.Text
dr!Start = w.StartTime
dr!End = w.EndTime
dr!Content = .Content.Content
dr!Location = .Locations(0).ValueString
End If
End With
If feed.NextChunk = Nothing Then
Exit While ' the data is delivered in "chunks"
End If
query.Uri = New Uri(feed.NextChunk)
feed = service.Query(query)
End While
For Each dr As DataRow In dt.Select("", "Start") ' now get the events based on start time
With dr

See: Sorting photo data from Google's Picasa API for a later description of the API.

No comments: