@peter-hudec
Reusing the same thread for a new problem encountered. I can only make one PUT/POST/GET request with each login. I can't reuse the login 'result' object.
The first time I make a request to get all events in Google Calendar. I check whether my own events exist in Google Calendar. If it doesn't exist, add them to Google Calendar.
The code below works in separate pages but not in one single login session in the same page.
provider_name = 'google'
response = make_response()
print 'Response', response
result = authomatic_inst.login(WerkzeugAdapter(request, response), provider_name)
print 'Result', (result)
if result:
if result.user:
# Get user info
result.user.update()
# Talk to Google Calendar API
if result.user.credentials:
response = result.provider.access('https://www.googleapis.com/calendar/v3/calendars/<CALENDARID>/events?key=<YOUR_API_KEY>', method='GET')
if response.status == 200:
items = response.data.get('items', {})
### <code to Check whether event exists in Google Calendar before adding it in>
# IF event not in Google Calendar, add it
body_json = json.dumps(event)
response = result.provider.access('https://www.googleapis.com/calendar/v3/calendars/<CALENDARID>/events?key=<YOUR_API_KEY>', method='POST', body=body_json, headers={'Content-Type':'application/json;charset=UTF-8'})
if response.status == 200:
res = response.data
return json.dumps(res)
Old question below:
I'm using Authomatic for managing OAuth2.0 logins.
I followed this [answer][1] posted by the creator. It works for YouTube authorisation, but not for Google Calendar.
http://peterhudec.github.io/authomatic/reference/classes.html#authomatic.Authomatic.access
if result: if result.user: # Get user info result.user.update() # Talk to Google Calendar API if result.user.credentials: response = result.provider.access('https://www.googleapis.com/calendar/v3/calendars/<calendarid>/events?key=<authkey>',
method='GET') if response.status == 200: print response
return response
The [GET request][2] with an interactive example as provided by Google Calendar API is:
GET https://www.googleapis.com/calendar/v3/calendars/<CALENDARID>/events?key={YOUR_API_KEY} Authorization: Bearer ya29.BwGoAyc8yqYGzDz3FEPn-_zYU_EFLy0hiQzbv1h9zOnzlJe4dw1q68WNLuW7weJKNjtYYcy3P_AbsA X-JavaScript-User-Agent: Google APIs Explorer
I'm pretty sure I'm using the same request but I'm getting error code 403 Forbidden?
[1]: https://stackoverflow.com/a/21987075/3583980 [2]: https://developers.google.com/google-apps/calendar/v3/reference/events/list