8

我在 Google Apps 脚本中有一个日历事件,我想允许用户通过单击锚点来打开它。我想我可以让 URL 看起来像这样:http://www.google.com/calendar/event?eid=SOMEID&ctz=Etc/GMT。但是我似乎无法从日历事件中获得所需的 ID。我从 Event.getId() 获得的 ID 在这些 URL 中不起作用,并且没有 event.getUrl()。

有谁知道这是否可以通过应用程序脚本实现?

4

6 回答 6

17

对于CalendarEvent和 givenevent类型的给定对象,构建 URL 以在 Google 日历应用中查看/编辑相应事件的最简单且有效的方法如下:calendarId

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

最好的事情是不需要 Google API 调用、身份验证……!

于 2015-10-23T12:42:34.610 回答
3

新版本的谷歌日历打破了这一点。以下是解决方法:

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('=','');
于 2017-11-24T23:25:11.713 回答
3

好吧...在 2020 年,这是此版本的工作版本,以防有人仍在为此苦苦挣扎...

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;   
于 2020-05-07T09:47:10.457 回答
0

这确实是不可能的。应用程序脚本问题跟踪器上有一个增强请求,其中提到了此错误功能。您可能希望启动它以跟踪更新和投票。

问题 627:约会的 GAS

于 2012-05-11T15:23:58.657 回答
0

当使用 Google 日历 Web 界面为 Google 日历创建事件时,eventId 类似于:

7ik7jal8upcnqu30koq3ctj4tn@google.com

并且可以使用以下内容获取事件的 url:

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);

不幸的是,相同的方法不适用于在 Outlook 桌面中创建的同一日历中的事件,而是生成如下的 eventId:

040000008200E00074C5B7101A82E00800000000D0E138AFF4C6D501000000000000000010000000C70DD9E87FE9EB46BCE437A98E9CC5BF

所以解决方案是不完整的,但现在使用 Outlook 桌面的人越来越少。

于 2020-06-12T22:21:28.293 回答
0

Use this code to get the id

var ati = cal.getId().indexOf("@");
var splitEventId = event.getId().split('@');
var eventUrl = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + cal.getId().substring(0,ati+2)).replace(/=/gi,'');
于 2021-10-05T10:33:39.863 回答