'Not correct scope for accessing events
HttpError at /calendar <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events?singleEvents=true&orderBy=startTime&alt=json returned "Request had insufficient authentication scopes.". Details: "[{'message': 'Insufficient Permission', 'domain': 'global', 'reason': 'insufficientPermissions'}]"> Request Method: GET Request URL: http://localhost:8000/calendar Django Version: 3.2.9 Exception Type: HttpError Exception Value:
Then does this after a while
RefreshError at /calendar The credentials do not contain the necessary fields need to refresh the access token. You must specify refresh_token, token_uri, client_id, and client_secret.
It seems I don't possess the right scope when accessing the calendar and it seems currently the access_token does appear.
from google.oauth2.credentials import Credentials
def get_user_events(request):
credentials = Credentials(get_access_token(request), scopes=SCOPES)
service = googleapiclient.discovery.build('calendar', 'v3', credentials=credentials)
google_calendar_events = service.events().list(calendarId='primary', singleEvents=True,
orderBy='startTime').execute()
google_calendar_events = google_calendar_events.get('items', [])
return google_calendar_events
def get_access_token(request):
social = request.user.social_auth.get(provider='google-oauth2')
return social.extra_data['access_token']
So the Scope I am using is the following
SCOPES = ['https://www.googleapis.com/auth/calendar']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
