I'm not getting permissions to create the event.
Below the code I'm using:
import httplib2
import os
import json
from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools
import datetime
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Insert Event'
def get_credentials():
"Gera as crendeciais"
#home_dir = os.path.expanduser('~')
credential_dir = os.path.join('credentials', '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir, 'calendar.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatability with Python 2.6
credentials = tools.run(flow, store)
print ('Storing credentials to ' + credential_path)
return credentials
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http)
title = 'teste de insercao'
day = '27'
month = '07'
year = '2015'
hourstart = '20'
minutestart = '00'
hourfinal = '20'
minutefinal = '30'
event = {
'summary': title,
'start': {
'dateTime': year + '-'+ month + '-'+ day + 'T' + hourstart + ':'+ minutestart +':00-03:00',
'timeZone': 'America/Sao_Paulo',
},
'end': {
'dateTime': year + '-'+ month + '-'+ day + 'T' + hourfinal + ':'+ minutefinal +':00-03:00',
'timeZone': 'America/Sao_Paulo',
},
'recurrence': [
'RRULE:FREQ=MONTHLY;COUNT=3'
],
'attendees': [
{'email': '[email protected]'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
}
create_event = service.events().insert(calendarId='primary', body=event, sendNotifications= False).execute()
print ('foi')
if __name__ == '__main__':
main()