Connecting to the Google Calendar API from C# or VB.NET

The Google calendar API is at its root very powerful, but you have not worked with XML/HTTP, cookies or authentication in the past learning the raw API can be daunting. Fortunately Google provides a free .NET library, so you can interact with a user’s Google Calendar using intuitive .NET classes and methods.

Add references to the Google libraries in your project, and use or import these in your code

using Google.GData.Client;
using Google.GData.Calendar;
using Google.GData.Extensions;

The library provides a “Service” class to handle connecting to and authenticating with Google:

Service service = new Service("cl", "companyName-appName-1");
service.setUserCredentials("useremail@userdomain.com", "userpassword");

You then execute a query on the service. The query will return a list of AtomEntry objects, which are handy wrappers for standard RSS Atom entries. For example, this returns a list of all items in the user’s calendar:

Google provides extensive documentation and sample code, in a dazzling variety of languages. Even Objective-C for you Mac developers.

As with any scenario where the data can be updated from multiple locations, your application will have to implement synchonization logic. The items you upload one day could be deleted from the web or from the user’s iPhone before your next sync. But fortunately the sometimes daunting task of communicating with the remote service is trivial in this case.