The Force.com Toolkit for Google Data APIs has just been announced here at Tour de Force Santa Clara. The goal of the toolkit is to make Google App services, starting with Spreadsheets, Documents and Calendar, first class citizens of the Force.com environment.
I got my hands on the toolkit yesterday and wrote a little integration app. Essentially I created events on my Google Calendar from within my Force.com app, and listed those events too. Here’s what the code looked like to list events:
CalendarService service = new CalendarService(); service.setAuthSubToken(fetchToken()); GoogleData.Calendar cal = service.getCalendarByTitle('TechCalendar'); GoogleData feed = service.getFeed( cal.alternate ); for( xmldom.element e: feed.entries) titles.add(new MyEvent(e.getValue('title'), e.getValue('content')));
As you can see, it takes about 5 lines of code to connect to a calendar and iterate through the events.
Creating an event is similarly straightforward:
CalendarService service = new CalendarService(); service.setAuthSubToken(fetchToken()); GoogleData.Calendar cal = service.getCalendarByTitle('TechCalendar'); Event ee = new Event( subject = 'Cool new Event', description = 'Clouds in the sky', ActivityDateTime = system.now(), DurationInMinutes = 120 ); service.insertEvent(cal, ee);
The only part that requires brain cycles in getting any of this to work was the authentication structure, which is part of the Google Data API architecture. Essentially you (as the Google Calendar user, for example) have the authenticate your application with Google, which requires a few page redirects and token exchanges. At the end of the day you end up with a token that you use in all subsequent interactions (see the
There’s plenty of documentation (and test coverage) to get you going, and as the code is open source you can go and scrabble around for yourself too. Here are all the bits:
- Force.com Toolkit for Google Data APIs – The Home Page
- Google Data APIs
- Google Data APIs Toolkit Setup
- Google Documents API
- Google Calendar API
- Google Spreadsheets API
- Blogger API
- Contacts API
- Google Data Authentication
- Browse the Toolkit code here
This opens the door to a lot of opportunities, so get coding!
See Ryan’s post on this over on the Google Data API Blog.