Google calendar api 获取google应用程序脚本中日历事件的链接(url)

Google calendar api 获取google应用程序脚本中日历事件的链接(url),google-calendar-api,google-apps-script,Google Calendar Api,Google Apps Script,我有一个在谷歌应用程序脚本,我想让用户打开它点击一个锚。 我想我可以,URL必须如下所示:。 但是,我似乎无法从日历事件中获取所需的ID。我从Event.getId()获取的ID在这些URL中不起作用,并且没有Event.getUrl() 有人知道应用程序脚本是否可以做到这一点吗?这确实是不可能的。应用程序脚本问题跟踪器上有一个增强请求,其中提到了此错误功能。您可能希望启动它来跟踪更新并投票支持它 对于给定的事件对象类型和给定的日历ID,在Google Calendar App中构建URL以查看

我有一个在谷歌应用程序脚本,我想让用户打开它点击一个锚。 我想我可以,URL必须如下所示:。 但是,我似乎无法从日历事件中获取所需的ID。我从Event.getId()获取的ID在这些URL中不起作用,并且没有Event.getUrl()


有人知道应用程序脚本是否可以做到这一点吗?

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


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

var splitEventId = event.getId().split('@');
var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + calendarId);
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);

最好的事情是,没有谷歌API调用,认证。。。需要

新版谷歌日历打破了这一点。以下是修复方法:

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

我注意到有两种类型的事件ID, 创建一系列事件时,只有一个链接可以传递给
yyyy/mm/dd
的参数,另一个链接将忽略给定的日期,并默认为今天的日期

看看这个日历:

转到11月,点击“计算机课程”活动,点击“更多详细信息”,它将带您到:

但通过检索eid的Bas64,它将返回
忽略传入的日期,如何获取ID?

好的。。。在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;   

使用Google calendar web界面为Google calendar创建事件时,eventId类似于:

7ik7jal8upcnqu30koq3ctj4tn@google.com

可以通过以下内容获取事件的url:

var splitEventId = event.getId().split('@');
var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + calendarId);
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 desktop中创建的相同日历中的事件,而Outlook desktop会生成如下eventId:

040000082000E00074C5B7101A82E0080000000D0E138AFF4C6D50100000000000000000C0070DD9E87FE9EB46BCE437A98E9CC5BF


因此,解决方案是不完整的,但现在使用Outlook desktop的人越来越少。

这非常有用!非常感谢。URL可能应该是
https://calendar.google.com/calendar/event?eid=
now Through:)提示:用于获取日历ID此答案已过时。如果你还有其他问题,请点击按钮提问。因为这是基于这个问题,我认为在这里提问会有好处。抱歉,如果这听起来很刺耳,当你有相关问题时,通常最好将其作为新问题提问并链接到旧问题。没有真正回答他们问题的答案可能会被删除,而你的(非常有效的)问题可能会丢失。谢谢