Google data APIs connect Cocoa developers to Google

Monday, April 16, 2007 at 6:51 AM

Posted by Greg Robbins, Software Engineer

When you trust your personal data to Google, it's still your data. You're free to edit it, to share it with others, or to download it and take it somewhere else entirely. The principle is simple: we won't lock you away from your data. In practice, we work hard to be sure that you and the software you use have the access that makes the principle really meaningful.

Last year, Google introduced Google data APIs, based on the Atom Publishing Protocol. Google data APIs are just a standard way to allow programs to get at your data on our servers. They already work with Google Calendar, Google Base, Blogger, and many other services. Google provides libraries to make it easy for programmers working in Java, C#, and Javascript to use the APIs.

The native language for Mac OS X applications is Objective-C, and it's our preferred language for Mac application development. To make it simpler for us to write Mac software that interacts with Google services, I created a framework to use Google data APIs directly in Objective-C programs. We are using the framework for our application development, and today we are making the framework available to all developers. The Google Data APIs Objective-C Library joins MacFUSE and Breakpad as open-source development efforts of Google's Mac software team, hosted at

A few small examples will give programmers an idea of how natural it is to use the framework to interact with Google services. Say an online roleplaying game wants to add a reminder to your Google Calendar that you need to be ready to join your guild in battle tonight between 10 and 11 pm. Adding the appointment to your calendar takes a few lines like this:

#import "GData/GData.h"

GDataServiceGoogleCalendar *service =
[[GDataServiceGoogleCalendar alloc] init];
[service setUserCredentialsWithUsername:@""

NSURL *calendarFeedURL =
[NSURL URLWithString:kGDataGoogleCalendarDefaultPrivateFullFeed];

GDataEntryCalendarEvent *newEvent =
[GDataEntryCalendarEvent calendarEvent];
GDataTextConstruct *content =
[GDataTextConstruct textConstructWithString:@"Battle today at 10pm"];

[newEvent setContent:content];
[newEvent setIsQuickAdd:YES];

[service fetchCalendarEventByInsertingEntry:newEvent

Or, if a screensaver wants to get the items you've advertised for sale on Google Base and animate them in a groovy fashion, this is how it would retrieve your stuff:

NSURL *baseFeedURL = [NSURL URLWithString:kGDataGoogleBaseUserItemsFeed];
[service fetchGoogleBaseFeedWithURL:baseFeedURL

The framework calls back into the screensaver with the list (called a feed) of Google Base items:

- (void)baseTicket:(GDataServiceTicket*)ticket
finishedWithFeed:(GDataFeedGoogleBase *)feed {
NSArray *myItems = [feed entries];

The framework also supports key-value coding, so it's quick and easy for Mac code chefs to use Cocoa bindings to whip up user interface displays of your information. Several sample Cocoa applications are available at to show how to use more features of the Google data APIs.

Google Calendar, Google Base, Google Spreadsheets, and generic Atom feeds like Blogger are supported now in the framework, with access to more services already in development. If you are a Mac developer, I hope you'll join the open-source project and help us make even more Mac applications Google-savvy.