How do I construct a link to a Google Calendar event?
Asked Answered
F

3

8

If I have the event ID of a Google Calendar event, for example:

[email protected]

How can I construct a URL to view the event details in the Google Calendar interface?

For example, if I go to a google calendar event, I see a URL such as this:

https://calendar.google.com/calendar/r/eventedit/NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw

What function/algorithm can I run to go from [email protected] to NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw?

Bonus: A bonus would be if there was also a shortcut method that worked on a CalendarEvent via Google Apps Script. For example, if there was a method such as getUrl() just like there is a getId() method.

Fireback answered 26/12, 2018 at 6:6 Comment(0)
F
20

Since the same event can exist in multiple calendars (e.g. by inviting others to it), the event id is not sufficient information.

To construct a URL you need both the event id (refresher for how find it), AND the Calendar ID (see below for instructions as to how to find it). You'll then need to encode both as base64, and finally you'll you have a valid Google Calendar event link.

For the following instructions, imagine we have an event, Event1, and it exists in both calendars, CalendarA and CalendarB.

In the Google Calendar interface, you would be able to view any of these combinations:

  • Event1 in CalendarA
  • Event1 in CalendarB

Let's assign the following IDs:

To construct an event URL:

  1. Get the event-id, which is the event id without the @google.com

    E.g. for Event1 we have 4htgpmm1hmak744r0kbkdcodar

  2. Get the calendar-id, which is the calendar id with the @group.calendar.google.com replaced with @g

    E.g. for CalendarA we have eugu9kan1ddi1pmi6sk3ib56g@g

  3. Join the two values with a space in the middle.

    <event-id> <calendar-id>
    

    E.g. for Event1 + CalendarA, we have:

    4htgpmm1hmak744r0kbkdcodar eugu9kan1ddi1pmi6sk3ib56g@g
    
  4. Encode the value as base64 (e.g. on https://www.base64decode.org):

    NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw==
    
  5. Remove the training ==:

    NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
    
  6. You can now append this value to https://www.google.com/calendar/event?eid= (view event page) or https://calendar.google.com/calendar/r/eventedit/ (edit event page):

    https://www.google.com/calendar/event?eid=NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
    
    or
    
    https://calendar.google.com/calendar/r/eventedit/NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
    
  7. You're done! That URL will take you to the calendar event in the Google interface.


How to find the calendar ID

If you need instructions for how to find the calendar id...

To find the calendar ID:

  1. Go to the calendar settings
  2. Scroll down until you find the calendar id field.

    This might be a value that ends with @group.calendar.google.com, your email address, or some other value.

If you are having trouble finding the calendar id, another tool that might help is adding the eventdeb=1 parameter to the URL, going to the Troubleshooting info of an event, and then looking for either the organizer or participant values, both of which contain calendar ids.


In Apps Script

var eventUrl = "https://www.google.com/calendar/event?eid=" +
                  Utilities.base64Encode(event.getId().split('@')[0] +
                  " " + 
                  event.getOriginalCalendarId())
                  .replace(/\=/g, '');
Fireback answered 26/12, 2018 at 6:6 Comment(2)
This is probably the most interesting answer about calendar service I've ever read. Still wondering where you got all these information 😄 Anyway, thanks a lot and again: congratulations!Amplitude
excellent answer, I added a few comments in a solution further down (as it's too long for a regular comment)Jeffjeffcoat
J
1

@Senseful had was a super helpful answer, and it works!

A few important things to note adding to the above. Firstly, when base64 encoding, you'll end up with a == at the end, remove that

Second, the base calendar URL will not work when the calendar the event belongs to does not belong in the primary account the user is logged in with. For example, if you're logged into 3 accounts, you'll have a different URL for each one e.g.

https://calendar.google.com/calendar/r/...

https://calendar.google.com/calendar/b/2/r/...

https://calendar.google.com/calendar/b/3/r/...

and so on... I don't think there's a solution that'll help with this situation since it's impossible to predict what accounts a specific user is logged into at any time.

Jeffjeffcoat answered 30/7, 2019 at 17:45 Comment(1)
Replacing the number 0,1,2 with the email address of the user (calendar) works. (calendar.google.com/calendar/b/[email protected]/r/...)Carrara
S
1

If your calendar ID is [email protected], then you can create link such as https://calendar.google.com/u/0/r/[email protected]

Sikko answered 2/10, 2023 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.