Reputation: 2382
Initially, I had the following scope:
SCOPES = ['https://www.googleapis.com/auth/calendar']
with the code:
credentials = google.oauth2.credentials.Credentials(
**flask.session['credentials'])
service = build('calendar', 'v3', credentials=credentials)
events_result =service.calendarList().list().execute()
events = events_result.get('items', [])
which worked well. However, as I don't require access to write/delete user calendar & to prevent user from getting
See, edit, share and permanently delete all the calendars that you can access using Google Calendar
& to protect their safety, I narrowed my scope down to
SCOPES = ['https://www.googleapis.com/auth/calendar.events.readonly']
with the same code. However, now I am getting:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json returned "Request had insufficient authentication scopes.". Details: "Request had insufficient authentication scopes.">
Even though the doc mentions you're able to execute such code to retrieve events with both of the scopes.
Upvotes: 2
Views: 1746
Reputation: 201388
events_result =service.calendarList().list().execute()
with the scope of https://www.googleapis.com/auth/calendar.events.readonly
. I thought that this might be the reason of your issue.When you want to retrieve the calendar list using your current script, please modify the scope to https://www.googleapis.com/auth/calendar.readonly
.
When you want to retrieve the event list, please modify your script as follows. In this case, the scope of https://www.googleapis.com/auth/calendar.events.readonly
can be used.
service = build('calendar', 'v3', credentials=creds)
events_result = service.events().list(calendarId='primary').execute()
events = events_result.get('items', [])
Upvotes: 1