In my previous post we looked at getting a list of calendars using the Google API. We looked at how to make the request, but not what to do with the data Google sends back.
When you make a request for a list of calendars, Google sends the list back in an xml format. Some of it is fairly self explanatory but some of it is a bit of a mystery. For that matter I’m still not 100% certain what all of it is for, but I want to focus your attention on one area of data that is important.
First do this:
<cfinvokeargument name="subSessionToken" value="abcdefgYOURSUBSESSION">
<cfinvokeargument name="gsessionid" value="abcdefgYOURGSESSION">
<cfinvokeargument name="includeAllCalendars" value="0">
This is assuming you’ve been following along with my other posts. When you run that code above it will display a data dump of the xml returned from Google.
Take a look at the “entry” sections. These are the individual calendars. (This is also assuming you’ve created at least one calendar) There should be an entry for each calendar. Drill down a little further and take a look at the various links, each calendar entry should have four links.
alternate – This URL gives you a list of all the entries for the calendar.
accessControlList – This URL gives you a list of who can modify the calendar
self – This URL provides the same basic information that you’re looking at now, except for ONLY one calendar
edit – This URL is what you use for editing the entries in a calendar
I think what you’ll find is that this is a very incomplete list of what you can do with the calendars. So personally i find this list to be a bit silly. For example, it doesn’t display the URL for batch processing. Of course in the docs it will say things like “send a DELETE request to the calendar’s edit URL” which is a pretty lame explanation. These URLs should be in the docs, not in the XML data.
What SHOULD be in this XML is the calendar ID. It’s there, just hidden. If you look at each of those URLs you’ll see the same string, most likely a URL-Encoded version of your gmail address, although not always. Basically on the end of each of those URLs is the ID for the calendar. If you look a little above the “link” values you’ll see an “ID” value. But it’s not just the calendar’s ID, it’s a full URL! Google doesn’t give you the basic ID directly (because that would be too easy!) you have to extract it out of the “ID” URL. No, it’s not hard, just messy.
That calendar ID (not the URL, the actual ID!) is important for our other methods. Here’s how to extract it from the “ID” URL:
So that will loop over each calendar and display the calendar’s actual ID for use with the other API methods. Now that we have the calendar ID, next we’ll look at editing a calendar.