May-28-2017, 09:01 AM
Hello Guys,
In this python script i am going to sync my google calendar events to the script.
I have gone through the setup of the API, I know that it works because if I just use the example script to show the next 10 events as given by Google it works fine.
But what issue i am facing is when i tried to create events it throws me the error.
In this python script i am going to sync my google calendar events to the script.
I have gone through the setup of the API, I know that it works because if I just use the example script to show the next 10 events as given by Google it works fine.
But what issue i am facing is when i tried to create events it throws me the error.
from __future__ import print_function
import httplib2
import os
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
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 = 'Google Calendar API Python Quickstart'
def get_credentials():
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-python-quickstart.json')
store = 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:
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)
GMT_OFF = '+05:30'
event = {
'summary': 'Dinner with friends',
'start': {'dateTime': '2017-05-28T19:00:00%s' % GMT_OFF},
'end': {'dateTime': '2015-05-28T22:00:00%s' % GMT_OFF},
}
event = service.events().insert(calendarId='primary', body=event).execute()
print('Event created: %s' % (event.get('htmlLink')))
if __name__ == '__main__':
main()I cannot get past the following error:Output:Traceback (most recent call last):
File "C:\Users\Meeran Rizvi\Documents\To-do-list\quickstart2.py", line 78, in <module>
main()
File "C:\Users\Meeran Rizvi\Documents\To-do-list\quickstart2.py", line 71, in main
event = service.events().insert(calendarId='primary', body=event).execute()
File "C:\Python27\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Python27\lib\site-packages\googleapiclient\http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json returned "Insufficient Permission">
[Finished in 1.8s]
