我正在使用Google Calendar API,併成功地將一個事件插入授權的主日曆中,但我想要硬編碼多個事件,這些事件在執行時,將填充用戶日曆。Google Calendar API:插入多個事件(使用Python)
例如:
- 6月24日下午1:00 「買蘋果」
- 6月26日下午3:00 「拿起衣服」
- 8月21日下午1:00 「清潔汽車」
- 9月1日下午2:00 「還書」
我的代碼現在的問題是:
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
try:
import argparse
flags = argparse.ArgumentParser(parents=
[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json',
SCOPES)
creds = tools.run_flow(flow, store, flags) \
if flags else tools.run(flow, store)
CAL = build('calendar', 'v3', http=creds.authorize(Http()))
GMT_OFF = '-04:00' # ET/MST/GMT-4
EVENT = {
'summary': 'Buy apples',
'start': {'dateTime': '2017-06-24T13:00:00%s' % GMT_OFF},
'end': {'dateTime': '2017-06-24T14:00:00%s' % GMT_OFF},
}
e = CAL.events().insert(calendarId='primary',
sendNotifications=True, body=EVENT).execute()
print('''*** %r event added:
Start: %s
End: %s''' % (e['summary'].encode('utf-8'),
e['start']['dateTime'], e['end']['dateTime']))
我需要知道如何在同一時間加入剩餘的事件,作爲一個例子,日曆。一個Google日曆事件插入中的多個非週期性事件。
傳遞事件的數組你是什麼如何將剩餘的事件添加到平均日曆在同一時間,我可以看到你可以添加一個事件,同樣你可以添加其他人,有什麼問題 –
我需要添加更多的事件,但是如果我添加另一個事件,它只會添加第一個事件。如果我通過「EVENT =」添加另一個,它會添加上面提到的事件。如果我通過「EVENT2 =」添加另一個事件,它將忽略它。 –