Nathan
Nathan

Reputation: 305

Google Calendar - Get shareable link via API / get 'cid' value for a calendar

Can I get a Google Calendar's 'cid' value via the API?

The 'id' returned in a Google Calendar Service API list/insert function is not very useful (unlike the usefulness of the 'id' when working with Google Drive service). Using the returned 'id' I can build a URL to the public calendar, but what I really want to do is build the URL to add the calendar to your calendars. The same one that is made when you go to a calendar's settings and click "Get Shareable Link".

The shareable link looks like this:

https://calendar.google.com/calendar?cid=reallyLongSequenceOfLettersAndNumber

If I can just get that 'cid' value programmatically...

Here is the data returned when using the API to list calendars: enter image description here

Upvotes: 3

Views: 1555

Answers (1)

Nathan
Nathan

Reputation: 305

I found the answer here.

It turns out the 'id' returned is the 'cid' in base64 encoding. Apparently sometimes the original 'id' will work as the 'cid'.. reference the link above for more info.

My python function to translate the 'id' into base64 is as follows:

    def getCalenderCID(calendarId):
        calendarId_bytes = calendarId.encode('utf-8')
        cid_base64 = base64.b64encode(calendarId_bytes)
        cid = cid_base64.decode().rstrip('=')
        return cid

Upvotes: 5

Related Questions