使用查询参数 "q" 筛选 google 日历事件列表
Filter google calendar event list with the query parameter "q"
我正在尝试使用参数 q= "status ='confirmed'"
从我的 Google 日历中过滤最近更新的事件列表,但它 returns 没有。
我第一次有这样的代码块:
def main():
watchEvents(monday) # monday is in isoformat : "2021-09-13T00:00:00Z"
def watchEvents(day):
page_token = None
while True:
events = service.events().list(calendarId='primary', pageToken=page_token, updatedMin=day).execute()
for event in events['items']:
print (event['summary'])
page_token = events.get('nextPageToken')
if not page_token:
break
但是参数 updatedMin=day
输出错误 Traceback (most recent call last): print (event['summary']) KeyError: 'summary'
,因为取消的事件没有这些属性。
这是我在 google site:
上尝试 API 时取消事件的示例
"items": [
{
"kind": "calendar#event",
"etag": "\"xxxxxxx\"",
"id": "xxxxx",
"status": "cancelled"
}
我不想要那些状态为“已取消”的事件类型,所以我在我的代码中尝试了参数 q= "status ='confirmed'"
:
events = service.events().list(calendarId='primary', pageToken=page_token, updatedMin=day, q= "status ='confirmed'").execute()
但现在它 returns 是一个空列表,即使我在 google site 上尝试 API 也是如此:
{
"kind": "calendar#events",
"etag": "\"xxxxx\"",
"summary": "FirstName Name private",
"updated": "2021-09-16T10:04:02.008Z",
"timeZone": "Europe/Brussels",
"accessRole": "owner",
"defaultReminders": [
{
"method": "popup",
"minutes": 30
}
],
"nextSyncToken": "XXXXXXXXX=",
"items": []
}
所以我的问题是:
- 过滤事件状态的语法是什么?
- 或者有其他方法可以获取最近更新的项目列表吗?
答案:
Google 日历 API 总是 returns 取消了 events: list
的事件,而 updateMin
或 syncToken
是在请求中指定。如果您想删除已删除的更新项目,则需要在本地完成。
更多信息:
根据事件资源文档:(强调我自己的):
Property name
Value
Description
Notes
status
string
Status of the event. Optional. Possible values are:
• "confirmed
" - The event is confirmed. This is the default status.
• "tentative
" - The event is tentatively confirmed.
• "cancelled
" - The event is cancelled (deleted). The list method returns cancelled events only on incremental sync (when syncToken
or updatedMin
are specified) or if the showDeleted
flag is set to true. The get method always returns them.
writable
来自 events: list
:
Parameter name
Value
Description
updatedMin
datetime
Lower bound for an event's last modification time (as a RFC3339 timestamp) to filter by. When specified, entries deleted since this time will always be included regardless of showDeleted
. Optional. The default is not to filter by last modification time.
您可以使用 syncToken
从上次发出同步请求时检索更新,但即便如此,也会返回 cancelled
事件。
此外,似乎无法使用 q
参数指定事件状态以在响应中过滤结果。
我正在尝试使用参数 q= "status ='confirmed'"
从我的 Google 日历中过滤最近更新的事件列表,但它 returns 没有。
我第一次有这样的代码块:
def main():
watchEvents(monday) # monday is in isoformat : "2021-09-13T00:00:00Z"
def watchEvents(day):
page_token = None
while True:
events = service.events().list(calendarId='primary', pageToken=page_token, updatedMin=day).execute()
for event in events['items']:
print (event['summary'])
page_token = events.get('nextPageToken')
if not page_token:
break
但是参数 updatedMin=day
输出错误 Traceback (most recent call last): print (event['summary']) KeyError: 'summary'
,因为取消的事件没有这些属性。
这是我在 google site:
"items": [
{
"kind": "calendar#event",
"etag": "\"xxxxxxx\"",
"id": "xxxxx",
"status": "cancelled"
}
我不想要那些状态为“已取消”的事件类型,所以我在我的代码中尝试了参数 q= "status ='confirmed'"
:
events = service.events().list(calendarId='primary', pageToken=page_token, updatedMin=day, q= "status ='confirmed'").execute()
但现在它 returns 是一个空列表,即使我在 google site 上尝试 API 也是如此:
{
"kind": "calendar#events",
"etag": "\"xxxxx\"",
"summary": "FirstName Name private",
"updated": "2021-09-16T10:04:02.008Z",
"timeZone": "Europe/Brussels",
"accessRole": "owner",
"defaultReminders": [
{
"method": "popup",
"minutes": 30
}
],
"nextSyncToken": "XXXXXXXXX=",
"items": []
}
所以我的问题是:
- 过滤事件状态的语法是什么?
- 或者有其他方法可以获取最近更新的项目列表吗?
答案:
Google 日历 API 总是 returns 取消了 events: list
的事件,而 updateMin
或 syncToken
是在请求中指定。如果您想删除已删除的更新项目,则需要在本地完成。
更多信息:
根据事件资源文档:(强调我自己的):
Property name Value Description Notes status
string
Status of the event. Optional. Possible values are:
• "confirmed
" - The event is confirmed. This is the default status.
• "tentative
" - The event is tentatively confirmed.
• "cancelled
" - The event is cancelled (deleted). The list method returns cancelled events only on incremental sync (whensyncToken
orupdatedMin
are specified) or if theshowDeleted
flag is set to true. The get method always returns them.writable
来自 events: list
:
Parameter name Value Description updatedMin
datetime
Lower bound for an event's last modification time (as a RFC3339 timestamp) to filter by. When specified, entries deleted since this time will always be included regardless of showDeleted
. Optional. The default is not to filter by last modification time.
您可以使用 syncToken
从上次发出同步请求时检索更新,但即便如此,也会返回 cancelled
事件。
此外,似乎无法使用 q
参数指定事件状态以在响应中过滤结果。