New frontiers with Google Data APIs and Objective-C

Thursday, March 20, 2008 at 11:54 AM



I work on Mac client software because I enjoy the compile-link-run cycle that is central to crafting great experiences for users. But we live in a client-server world, and Google has world-class servers and web applications. That's why Google Data APIs are so cool if you develop Mac software: you don't need to build your own server farms and write your own web interfaces. Just let your software talk directly to Google's servers.

With the recent release of the Google Contacts Data API and the YouTube API for browsing and uploading, developers now have two more ways to reach users. Today's release of version 1.4 of the GData Objective-C Client Library adds support for these new APIs. Any Mac program that creates video can easily let users upload the video to a YouTube account. Mac software can also now enable users to access or edit their Google account contacts.

It's easy and natural for Cocoa programmers to use the library. This code snippet shows how get the names of all contacts in a user's Gmail account address book:

#import "GData/GDataContacts.h"

- (void)fetchContacts {
GDataServiceGoogleContact *service =
[[GDataServiceGoogleContact alloc] init];
[service setUserCredentialsWithUsername:@"myaccount@gmail.com"
password:@"mypassword"];
NSURL *feedURL =
[NSURL URLWithString:kGDataGoogleContactDefaultBaseFeed];

[service fetchContactFeedWithURL:feedURL
delegate:self
didFinishSelector:@selector(ticket:finishedWithContactFeed:)
didFailSelector:@selector(ticket:failedWithError:)];
}

- (void)ticket:(GDataServiceTicket *)ticket
finishedWithContactFeed:(GDataFeedContact *)feed {

NSArray *names =
[feed valueForKeyPath:@"entries.title.stringValue"];
}

- (void)ticket:(GDataServiceTicket *)ticket
failedWithError:(NSError *)error {
NSLog(@"%@", error);
}

Uploading video takes just a bit more effort, because YouTube's API requires metadata describing the video along with the video data itself. The Objective-C GData Library includes sample code showing how to do these and other common tasks with the APIs.

And one more thing...

The source code for the GData Objective-C Client Library is now compatible with the iPhone SDK as well. Perhaps you want your iPhone software to send photos to a Picasa Web Albums account, or keep a journal of phone calls automatically in Blogger. Maybe your iPhone application accesses a database of information from a Google Spreadsheet or from Google Base. With the Google Data APIs Objective-C Client Library, creating software for these tasks is straightforward.

If you are writing iPhone software, just drag the "GData Sources" group folder from the GData project file into your iPhone project, and use the GData APIs as you would when writing a Mac application. The Objective-C Client Library is an open-source project, so you can find links to the sources and documentation on the project page.