首页 > 解决方案 > 使用 Python 从 google 日历 api 获取所有假期的列表

问题描述

我已经勾选了所有要添加到我的谷歌日历的国家。现在,使用 google api,我正在尝试检索所有的假期,每天。

到目前为止,我有:

from __future__ import print_function
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials

SCOPES = ['https://www.googleapis.com/calendar/v3/calendars/primary/holiday']
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
service = build('calendar', 'v3', credentials=creds)

events = service.events().list(calendarId='primary', timeMin = '2021-01-01T00:00:00Z',
                              timeMax='2022-01-02T00:00:00Z').execute()

只返回

{'kind': 'calendar#events',
 'etag': '"p32kbjd5mnaof20g"',
 'summary': 'ncl.rm.business.analysis@gmail.com',
 'updated': '2021-06-24T14:15:13.401Z',
 'timeZone': 'America/New_York',
 'accessRole': 'owner',
 'defaultReminders': [{'method': 'popup', 'minutes': 30}],
 'nextSyncToken': 'CKi5tLa6sPECEKi5tLa6sPECGAUguITQtQE=',
 'items': []}

无论我的事件/范围变量发生什么变化。

标签: pythongoogle-apicalendar

解决方案


推荐阅读