Get link (url) to an calendar event in google apps script

后端 未结 6 918
后悔当初
后悔当初 2020-12-17 00:55

I have a Calendar Event in Google Apps Script and I want to allow the user to open it by clicking an Anchor. I think I can the URL has to look like this: http://www.google.

相关标签:
6条回答
  • 2020-12-17 01:17

    I noticed there are two type of event ID's, when creating a series of events, there is only one link that you can pass on arguments of the yyyy/mm/dd, the other one will ignore the given date and will just default in todays date.

    Look at this calendar: https://calendar.google.com/calendar/embed?src=vpaacademy.com_id182o7e82j7f4es5jrefink2g%40group.calendar.google.com&ctz=America%2FNew_York

    Go to November and Click on 'Computer class' event, click on "More details" it will bring you to: https://calendar.google.com/calendar/r/month/2018/10/29?eid=MWVqMjBjYmFhMGVrMnA3YTB0bGN0ajJjNzhfMjAxODEwMjlUMjMzMDAwWiB2cGFhY2FkZW15LmNvbV9pZDE4Mm83ZTgyajdmNGVzNWpyZWZpbmsyZ0Bn&ctz=America/New_York&sf=true

    but by retriving the Bas64 of the eid it returns https://calendar.google.com/calendar/r/month/2018/10/29?eid=MWVqMjBjYmFhMGVrMnA3YTB0bGN0ajJjNzggdnBhYWNhZGVteS5jb21faWQxODJvN2U4Mmo3ZjRlczVqcmVmaW5rMmdAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ= which ignores the date passed in, how can I get that ID?

    0 讨论(0)
  • 2020-12-17 01:21

    For given event object of type CalendarEvent and given calendarId, the simplest and working way to build an URL to view/edit corresponding event in Google Calendar App is the following:

    var splitEventId = event.getId().split('@');
    var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + calendarId);
    

    The best thing is that no Google API invocation, authentication, ... needed!

    0 讨论(0)
  • 2020-12-17 01:22

    The new version of Google Calendar has broken this. Here's how to fix it:

    var mycal = 'username@m'
    var splitEventId = event.getId().split('@');
    var eventUrl = "https://www.google.com/calendar/event?eid=" + 
    Utilities.base64Encode(splitEventId[0] + " " + mycal).toString().replace('=','');
    
    0 讨论(0)
  • 2020-12-17 01:22

    It is indeed not possible. There's an enhancement request on apps script issue tracker that mentions this misfeature. You may want to start it to keep track of updates and kind of vote for it.

    Issue 627: GAS for Appointments

    0 讨论(0)
  • 2020-12-17 01:27

    Allright... In 2020 this is the working version of this in case somebody is still struggling with this...

    var calendarID = "somec@lend.ar";
    var event = CalendarApp.getCalendarById(calendarID).createEvent(/*SOME OPTIONS HERE*/);
    
    var splitEventId = event.getId().split('@');
    
    // Open the "edit event" dialog in Calendar using this URL:
    var event_EDIT_URL = "https://calendar.google.com/calendar/r/eventedit/" + Utilities.base64Encode(splitEventId[0] + " " + calendarID).replace("==",'');
    
    // Open the "view this event in a Calendar" using this URL:
    var event_VIEW_IN_CAL_URL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + calendarID).replace("==",'');
    
    
    return event_EDIT_URL; // OR return event_VIEW_IN_CAL_URL;   
    
    0 讨论(0)
  • 2020-12-17 01:28

    When an event is created for a Google calendar using the Google calendar web interface an eventId looks something like:

    7ik7jal8upcnqu30koq3ctj4tn@google.com

    and it is possible to get a url for the event with the following:

    var calendarId = 'domain.ac.uk_6l495bdvjmo1felggasrvclkc4@group.calendar.google.com';
    var eventId = '7ik7jal8upcnqu30koq3ctj4tn@google.com';
    var splitEventId = eventId.split('@');
    var eventURL = 'https://calendar.google.com/calendar/r/eventedit/' + Utilities.base64Encode(splitEventId[0] + ' ' + calendarId);
    
    //Or for a recurring event
    var event = CalendarApp.getCalendarById(calendarId).getEventById(eventId);
    var moment = Moment.moment;
    var startTime = moment(event.getStartTime()).utc().format('YMMDDTHHmmss')+'Z';
    var eventURL = 'https://calendar.google.com/calendar/r/eventedit/' + Utilities.base64Encode(splitEventId[0] + '_' +startTime+ ' ' + calendarId);
    

    Unfortunately the same method doesn't work for events in the same calendar created within Outlook desktop, which instead produces an eventId like this:

    040000008200E00074C5B7101A82E00800000000D0E138AFF4C6D501000000000000000010000000C70DD9E87FE9EB46BCE437A98E9CC5BF

    So the solution is incomplete but many less people use Outlook desktop these days.

    0 讨论(0)
提交回复
热议问题