使用Google API(Python)插入日历

使用Google API(Python)插入日历,python,insert,google-api,calendar,google-calendar-api,Python,Insert,Google Api,Calendar,Google Calendar Api,我想使用GoogleAPI插入一个辅助日历。我用过谷歌的解释,但我自己似乎做不到。您如何使用: calendar = { 'summary': 'calendarSummary', 'timeZone': 'America/Los_Angeles' } created_calendar = service.calendars().insert(body=calendar).execute() print created_calendar['id'] 因此,如果要添加辅助日历,请使用c

我想使用GoogleAPI插入一个辅助日历。我用过谷歌的解释,但我自己似乎做不到。您如何使用:

calendar = {
'summary': 'calendarSummary',
'timeZone': 'America/Los_Angeles'
}

 created_calendar = service.calendars().insert(body=calendar).execute()

 print created_calendar['id'] 

因此,如果要添加辅助日历,请使用curl:

curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer here_add_access_token"  https://www.googleapis.com/calendar/v3/calendars -d {'summary':'here_calendar_name'}
在Python中是:

import requests

url = "https://www.googleapis.com/calendar/v3/calendars

headers = {
        'Content-Type': "application/json",
        'Authorization': "Bearer access_token"
    }
payload = {
        'summary': 'Google Calendar secondary',
    }

response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
response = response.text

我们可以问一下日历API的错误、作用域和条件吗?请尝试:import argparse flags=argparse.ArgumentParser(parents=[tools.argparser])。parse_args()除了ImportError之外:flags=None scopes=''store=file.Storage('Storage.json')creds=store.get()如果不是creds或creds.invalid:flow=client.flow\u from\u clientsecrets('client\u secret.json',SCOPES)creds=tools.run\u flow(flow,store,flags)\if flags else tools.run(flow,store)