如何找到我的 Google 日历活动的活动 ID?
How can I find the Event Id of my Google Calendar event?
我创建了一些 Google 日历事件,现在我想以编程方式对它们执行一些操作。
麻烦的是我没有他们的身份证。
当我进入日历并点击活动时,我在任何地方都看不到 ID。
有人知道我在哪里可以找到它吗?
- 获取校准
- 遍历相关时间段内的所有事件
function myFunction() {
var cal = CalendarApp.getCalendarById(id);
var events = cal.getEvents(startTime, endTime);
for ( var i in events ) {
var id = events[i].getId();
}
}
简单的答案是 eventId = event.get('id')。
您没有询问事件对象,但作为其他人的指南,这就是我为我的 Google 日历 python 脚本创建它的方式:
creds = get_credentials()
http = creds.authorize(httplib2.Http())
calendar_service = discovery.build('calendar', 'v3', http=http)
event = calendar_service.events().insert(calendarId='primary',
body=event).execute()
然后
eventId = event.get('id')
在 Google 日历网站上
因为他最初询问如何单击进入日历并找到特定事件的 ID,因为这也是我需要知道如何做的:
单击您的 Google 日历中的活动。
它将带您到带有 URL 的页面,例如 https://calendar.google.com/calendar/render?pli=1#eventpage_6%7Ceid-NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw-1-0-
在URL中寻找"eid"。
Select 并复制 eid-
和下一个 -
之间的字符串。 (在我这里的示例中,它是 NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
。)
现在需要从Base64格式解码。您可以将该字符串粘贴到工具中,例如 https://www.base64decode.org/.
结果将是两个由 space 分隔的字符串。第一个字符串是您的事件 ID。
还有另一种查看事件 ID 的方法。
- 在 https://www.google.com/calendar/render?gsessionid=OK&eventdeb=1
转到事件调试 URL
- 双击查看受影响的事件。
- Select 下拉菜单 'More Actions'.
- 单击 'Troubleshooting Info'。
- 复制显示的文本并将其粘贴到您对支持人员的回复中。
还有另一种快速简便的方法。
- 点击日历中的活动。它不需要处于调试模式。
- 从 URL 复制最后一个斜线和问号之间的字符串。
- 将此字符串粘贴到 base64 编码器中。 (https://www.base64decode.org/)
- 您将获得活动 ID 和日历所有者(您?)的电子邮件。
- (eventId为第一串字符)
TL;DR
为此您应该使用高级 API。
Calendar.Events.list(calendarId).items[0].id; // returns the id of the first event
如果您只需要特定事件的事件 ID 并且可以使用手动方法,。
如果您需要程序化解决方案,请注意您不能使用标准 API (CalendarApp
),因为 CalendarEvent
上 getId()
的文档指出:
Gets the unique iCalUID of the event. Note that the iCalUID and the event id used by the Calendar v3 API and Calendar advanced service are not identical and cannot be used interchangebly. One difference in their semantics is that in recurring events all occurrences of one event have different ids while they all share the same iCalUIDs.
这意味着如果您想为重复发生的事件构建 URL,您将 运行 陷入问题,因为您无法正确使用 getId(),尤其是对于重复发生的事件。最好的解决方法是使用高级日历 API。 (另请注意,如果您尝试 ,高级 API 甚至有一个 htmlLink
属性 和编码的 calendarId + realEventId。
这里有一些关于为什么 getId()
它会因重复事件而中断的更多详细信息:这是因为当您对重复的事件调用 event.getId()
时,您会得到相同的 ID。无法使用简单的日历 API 来引用日历事件的特定实例。 URL 仍然可以通过附加 _20190626T000000Z
等格式来引用事件的特定实例。但是,不清楚需要在那里提供什么值。还有一些情况是 _
被替换为 _R
和 Z
被替换为 @google.com
,这使事情更加复杂。
证明这是一个问题:
- 查找重复的日历事件。
- 解析它的URL(保证引用特定实例)。
- 调用
CalendarApp.getEventById(parsedId1).getId()
注意返回的值。
- 现在为事件的不同实例解析 URL。
- 调用
CalendarApp.getEventById(parsedId2).getId()
注意返回的值。 parsedId1
和parsedId2
虽然是不同的字符串(指具体实例),但两者的getId()
返回值是相同的。该事件实际上是对特定实例的引用,但您不能再序列化它们的 ID。
如果您真的想使用简单的日历 API,您可能需要某种同步过程并在 [=32] 期间在日历事件的每个实例上存储 metadata/tags =] 会让你的生活更轻松。
创建id的时候可以直接取,需要导入base64:
event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
}
event = service.events().insert(calendarId='primary', body=event).execute()
print(event['id'])
转到日历并单击事件,它会显示如下弹出窗口
现在点击 edit 图标,它会重定向到一个页面,然后从 url 找到 eventedit 这个参数之后你可以看到事件ID。 URL 喜欢下面
https://calendar.google.com/calendar/u/0/r/eventedit/OGM1dnRlODY4azBzMWtjdThzMmo3NmM2OWNfMjAyMTEwMjhUMTYwMDAwWiBuNXUzMTk5NTFyYjI18555FsdZwdWE4dWExb0Bn?pli=1
我创建了一些 Google 日历事件,现在我想以编程方式对它们执行一些操作。
麻烦的是我没有他们的身份证。
当我进入日历并点击活动时,我在任何地方都看不到 ID。
有人知道我在哪里可以找到它吗?
- 获取校准
- 遍历相关时间段内的所有事件
function myFunction() {
var cal = CalendarApp.getCalendarById(id);
var events = cal.getEvents(startTime, endTime);
for ( var i in events ) {
var id = events[i].getId();
}
}
简单的答案是 eventId = event.get('id')。 您没有询问事件对象,但作为其他人的指南,这就是我为我的 Google 日历 python 脚本创建它的方式:
creds = get_credentials()
http = creds.authorize(httplib2.Http())
calendar_service = discovery.build('calendar', 'v3', http=http)
event = calendar_service.events().insert(calendarId='primary',
body=event).execute()
然后
eventId = event.get('id')
在 Google 日历网站上
因为他最初询问如何单击进入日历并找到特定事件的 ID,因为这也是我需要知道如何做的:
单击您的 Google 日历中的活动。
它将带您到带有 URL 的页面,例如
https://calendar.google.com/calendar/render?pli=1#eventpage_6%7Ceid-NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw-1-0-
在URL中寻找"eid"。
Select 并复制
eid-
和下一个-
之间的字符串。 (在我这里的示例中,它是NGh0Z3BtbTFobWFrNzQ0cjBrYmtkY29kYXIgZXVndTlrYW4xZGRpMXBtaTZzazNpYjWoNmdAZw
。)现在需要从Base64格式解码。您可以将该字符串粘贴到工具中,例如 https://www.base64decode.org/.
结果将是两个由 space 分隔的字符串。第一个字符串是您的事件 ID。
还有另一种查看事件 ID 的方法。
- 在 https://www.google.com/calendar/render?gsessionid=OK&eventdeb=1 转到事件调试 URL
- 双击查看受影响的事件。
- Select 下拉菜单 'More Actions'.
- 单击 'Troubleshooting Info'。
- 复制显示的文本并将其粘贴到您对支持人员的回复中。
还有另一种快速简便的方法。
- 点击日历中的活动。它不需要处于调试模式。
- 从 URL 复制最后一个斜线和问号之间的字符串。
- 将此字符串粘贴到 base64 编码器中。 (https://www.base64decode.org/)
- 您将获得活动 ID 和日历所有者(您?)的电子邮件。
- (eventId为第一串字符)
TL;DR
为此您应该使用高级 API。
Calendar.Events.list(calendarId).items[0].id; // returns the id of the first event
如果您只需要特定事件的事件 ID 并且可以使用手动方法,
如果您需要程序化解决方案,请注意您不能使用标准 API (CalendarApp
),因为 CalendarEvent
上 getId()
的文档指出:
Gets the unique iCalUID of the event. Note that the iCalUID and the event id used by the Calendar v3 API and Calendar advanced service are not identical and cannot be used interchangebly. One difference in their semantics is that in recurring events all occurrences of one event have different ids while they all share the same iCalUIDs.
这意味着如果您想为重复发生的事件构建 URL,您将 运行 陷入问题,因为您无法正确使用 getId(),尤其是对于重复发生的事件。最好的解决方法是使用高级日历 API。 (另请注意,如果您尝试 htmlLink
属性 和编码的 calendarId + realEventId。
这里有一些关于为什么 getId()
它会因重复事件而中断的更多详细信息:这是因为当您对重复的事件调用 event.getId()
时,您会得到相同的 ID。无法使用简单的日历 API 来引用日历事件的特定实例。 URL 仍然可以通过附加 _20190626T000000Z
等格式来引用事件的特定实例。但是,不清楚需要在那里提供什么值。还有一些情况是 _
被替换为 _R
和 Z
被替换为 @google.com
,这使事情更加复杂。
证明这是一个问题:
- 查找重复的日历事件。
- 解析它的URL(保证引用特定实例)。
- 调用
CalendarApp.getEventById(parsedId1).getId()
注意返回的值。 - 现在为事件的不同实例解析 URL。
- 调用
CalendarApp.getEventById(parsedId2).getId()
注意返回的值。parsedId1
和parsedId2
虽然是不同的字符串(指具体实例),但两者的getId()
返回值是相同的。该事件实际上是对特定实例的引用,但您不能再序列化它们的 ID。
如果您真的想使用简单的日历 API,您可能需要某种同步过程并在 [=32] 期间在日历事件的每个实例上存储 metadata/tags =] 会让你的生活更轻松。
创建id的时候可以直接取,需要导入base64:
event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
}
event = service.events().insert(calendarId='primary', body=event).execute()
print(event['id'])
转到日历并单击事件,它会显示如下弹出窗口
现在点击 edit 图标,它会重定向到一个页面,然后从 url 找到 eventedit 这个参数之后你可以看到事件ID。 URL 喜欢下面
https://calendar.google.com/calendar/u/0/r/eventedit/OGM1dnRlODY4azBzMWtjdThzMmo3NmM2OWNfMjAyMTEwMjhUMTYwMDAwWiBuNXUzMTk5NTFyYjI18555FsdZwdWE4dWExb0Bn?pli=1