我正在尝试根据 Google 日历活动的位置更改其颜色。我想要更改的事件是带有网络呼叫链接的同步日历的一部分。我无法单独更改每个事件的颜色,但我可以设置日历的颜色。
以下代码允许我更改另一个非同步日历(我自己创建的)的各个事件的颜色,但对于同步日历,我收到错误403: Forbidden。 HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID/events/EVENT_ID?alt=json returned "Forbidden">
from apiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
scopes = ['https://www.googleapis.com/auth/calendar']
flow = InstalledAppFlow.from_client_secrets_file("client_secret.json", scopes=scopes)
credentials = flow.run_console()
service = build("calendar", "v3", credentials=credentials)
calId = "my_calendar_id"
calendar = service.events().list(calendarId=calId).execute()
keyword = "my_location_keyword"
for event in calendar['items']:
# I navigate through each event of the specified calendar
if 'location' in event and event['location'].find(keyword):
# if the location exists and contains the keyword, then i change the color
service.events().patch(calendarId=calId, eventId=event['id'], body={"colorId":10}).execute()
有没有办法改变颜色而不触发禁止的错误?在我看来,颜色不应该受到授权保护......
我考虑过将日历复制到我有写入权限的另一个日历中,并更改新日历上的颜色,但这似乎有点矫枉过正。还有更好的主意吗?
千万里不及你
相关分类