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

2019-03-27 10:12发布

问题:

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.com/calendar/event?eid=SOMEID&ctz=Etc/GMT . However I can't seem to get the required ID from the Calendar Event. The ID I get from Event.getId() doesn't work in those URL's and there is no event.getUrl().

Does anyone know if this is possible with apps script?

回答1:

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!



回答2:

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('=','');


回答3:

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



回答4:

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?