Tuesday, August 9, 2011

Fun with Google Calendar API (Sort of...)

I've been working with Google's Calendar API a bit, as of late, and I wanted to share a few hiccups I ran into in the hopes of avoiding them again, myself, and helping someone else. Some of this is certainly my own impatience with reading the (large amounts of "strangely" organized) documentation. I have a hard time imagining anyone sitting and reading this stuff from start to finish, so I end up Googling for help (how ironic). Here are some highlights:


  • When requesting a calendar feed, if you include "futureevents=true" in the URL, any start-max value you have in the string will be overridden. Sort of makes sense, but it seems arbitrary. In fact, if I go through the trouble of including a start-max, I would think that it should override futureevents (which, IMHO, is much easier to include accidentally on purpose, and has a fifty-fifty chance of being set to true). But whatever.
  • Requesting the "basic" version of a calendar will result in a very different response format. This sort of makes sense (since "basic" vs. "full" by definition defines the format). In particular, the start/end times are included in the "detail" part of the returned information, NOT in a "when" array, as they are with full. I thought this was strange since, regardless of how extensive the details are, I would expect the date/time information to have remained the same, whether I'm getting a lot of other details or not. (After all - isn't date and time what it's all about, anyway?)
  • This one didn't really trip me up, but I'll throw it in for good measure: setting singleevents=true in the query string returns individual event listings for each event, even if that event is recurring. In other words, you will get a unique event entry, for example, for every meeting on Tuesday that you can parse out individually. Otherwise, you get one mention of the Tuesday meeting with a bunch of dates/times attached to the one event. This is intuitive, really, but it makes a difference in dealing with a recurring event. Note that, in either case, the "when" data comes back as an array, so you still need to loop through it, even if it's an individual event with only one start and end date.
Here's a quick example of a feed request url:

https://www.google.com/calendar/feeds/atlanticstationatl%40gmail.com/public/full?alt=jsonc&start-min=2011-08-09T00:00:00&start-max=2011-08-30T00:00:00&orderby=starttime&sortorder=ascending&futureevents=false&singleevents=true

In it, I'm requesting a full calendar feed (so I get my "when" values) in the json-c format, with a start and end time as listed (note the standardized format it needs), ordered by the start time (ascending), with no future events (so that I don't override my end times), with recurring events treated as individual entries.

Good luck!

No comments:

Post a Comment