The Problem

In case you didn’t know: you can get all other google calendars using a very simple api:

  1. just go to your Google Calendar settings
  2. on the left under “Settings for my calendars” chose the one you want to export (usually the one with your name as name)
  3. scroll down to “Integrate Calendar”
  4. if this is a private calendar there will be a field “Secret address as iCal” with a hidden url inside. Otherwise there is just the other field: “Public address as iCal” with a url.
  5. when you curl that url, you simply get all events in this calendar (for the next two years it seems) as iCal. Neat :-)

However when you try the above steps with the calendar called “Birthdays” you will find that while you can embed it, there is no option for the iCal downloads. Not so Neat :-(

The Solution

Some googling revealed that for this calendar it’s simply not supported (at least not that easy). But there is a slightly more complicated Workaround:

  1. Get the calendar ID just below the “Integrate Calendar” there should be the calendar ID. I assume this is ust some placehoalder and everyone sees the same number here, but not sure.
  2. Escape it to a URI Google throws you a few curveballs and puts URL-control characters into that one. We need to escape them using e.g. this URL encoder.
  3. Setting up OAuth2 ~This is the part I haven’t yet figured out.~ I used Google’s OAuth Playground to put in my request. Of course google’s analytics fucks up the encoding of the result -_- The scope you need is https://www.googleapis.com/auth/calendar.readonly.

    If you want an automatic solution check out my other post How to Authenticate your bash script with Google.

  4. Query to CalDAV You may know about the CalendarAPI which does what we want but using some proprietary json format. However there is a small link to another API: CalDAV. There is absolutely no documentation on what this API does or how it works, but apparently it’s mostly compliant to rfc4791 and supported by Apple and Mozilla. This one communicates the same information in iCal.

    Just send this request:

    GET https://apidata.googleusercontent.com/caldav/v2/{your escaped calendar ID here}/events
    

    And you’ll get just what you need: All your google contacts birthdays of the next two years.

If you figure out how to get around the OAuth2, please send me an email. Supposedly you can somehow configure client secrets in your Google Cloud API Dashboard bit I haven’t gotten that to work yet.