iCal Files for Single Google Calendar Events

Over the past few months, I have been going round-and-round trying to figure out how to link to individual events in a Google Calendar, allowing visitors to add the event to their own calendars. Google does a nice job of providing functionality to add an event to your own Google calendar, but they don’t seem to offer any functionality to add an event to other calendars.

Google does, however, provide a link to an iCal file for each calendar’s feed; which allows you to add the calendar itself to your own calendar program (Outlook, etc.). The problem with that, obviously, is that, instead of adding a single event (maybe a concert or conference you want to attend, a public meeting, etc.), it adds all of the events from that calendar.

A Possible Solution

After a lot of digging, head-desking and testing, I think I might have found a solution, though. When you read an XML/Atom feed from a Google calendar, there is an <id> element for each event listed in the feed. That <id> element is actually a URL/permalink for the event, and leads to an XML file with just that event’s data in it.

Once I discovered that, I decided to do some further testing. In the Google calendar API reference, it mentions that you can use a URL structure like the following to get the feed for an individual event:

https://www.google.com/calendar/feeds/userID/visibility/projection/eventID

If you compare that to the URL structure that Google provides for an individual calendar’s feed (the whole calendar):

https://www.google.com/calendar/feeds/userID/visibility/projection

then compare that to the URL structure that Google provides for an individual calendar’s iCal feed (again, the whole calendar):

https://www.google.com/calendar/ical/userID/visibility/projection.ics

you might start to notice some similarities.

The Event’s iCal URL Structure

It turns out (I still have some testing to do, but my preliminary testing indicates that it works), if you use a URL structure like the following, you should be able to grab an iCal file (.ics) for an individual event:

https://www.google.com/calendar/feeds/userID/visibility/projection/eventID.ics

So, how do you do that? Well, simply grab the value of the <id> element from the calendar feed, then replace the string /feeds/ with the string /ical/ and append the file extension .ics to the end.

A Potential Issue

One last potential issue arises when you do that, though. Outlook (and, presumably, other calendar programs) still interprets the downloaded .ics file as a calendar feed rather than an individual event/appointment. When you open the file in Outlook, rather than displaying the normal “Appointment” edit dialog, it actually opens it as an entirely new calendar.

That can be corrected, though, by cracking open the downloaded .ics file and removing the line that begins with:

X-WR-CALNAME:

Once that line is no longer in the .ics file, Outlook will open the file as an individual event/appointment for you to save to your calendar, rather than opening it as a whole new calendar.

Obviously, you wouldn’t want to require your users to do that themselves, so you’d probably want to write your own script that retrieves the file from Google’s server (possibly caching it for a while if you don’t edit events very often), locates the line mentioned above, removes it, saves the file in a temporary location on your server and then prompts the user to download it.

Thoughts?

As I mentioned, I still have some testing to do with this, but I’d love feedback on the concept. Have you tried this before? Am I missing anything obvious?

2 Responses

  • Vietnam

    Thanks for writing great post

  • Rob Arends

    Great post, confirmed what I’d seen elsewhere, but it doesn’t work in Nov 2013.
    I can get the eventid xml, but if I swap the ‘feeds’ to ‘ical’ and suffix ‘.ics’ I get ‘404 not found’.

    I’ve tried public and private versions of the url.
    Does this work for you? Is there any other trick to it?

    Rob.