title: Google Calendar API using REST - only one request per auth?
body: <p>@peter-hudec </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>The code below works in separate pages but not in one single login session in the same page.</p>
  
  <pre><code>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/&lt;CALENDARID&gt;/events?key=&lt;YOUR_API_KEY&gt;', method='GET')
              if response.status == 200:
                  items = response.data.get('items', {})
  
                  ### &lt;code to Check whether event exists in Google Calendar before adding it in&gt;
                  # IF event not in Google Calendar, add it 
  
                      body_json = json.dumps(event)
                      response = result.provider.access('https://www.googleapis.com/calendar/v3/calendars/&lt;CALENDARID&gt;/events?key=&lt;YOUR_API_KEY&gt;', method='POST', body=body_json, headers={'Content-Type':'application/json;charset=UTF-8'})
                      if response.status == 200:
                          res = response.data
                      return json.dumps(res)
  </code></pre>
  
  <p>Old question below:</p>
  
  <blockquote>
    <p>I'm using Authomatic for managing OAuth2.0 logins.</p>
    
    <p>I followed this [answer][1] posted by the creator. It works for
    YouTube authorisation, but not for Google Calendar.</p>
    
    <p><a href="http://peterhudec.github.io/authomatic/reference/classes.html#authomatic.Authomatic.access" rel="nofollow noreferrer">http://peterhudec.github.io/authomatic/reference/classes.html#authomatic.Authomatic.access</a></p>
  
  <pre><code>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/&lt;calendarid&gt;/events?key=&lt;authkey&gt;',
  </code></pre>
    
    <p>method='GET')
                        if response.status == 200:
                            print response</p>
  
  <pre><code>return response
  </code></pre>
    
    <p>The [GET request][2] with an interactive example as provided by Google
    Calendar API is:</p>
  
  <pre><code>GET https://www.googleapis.com/calendar/v3/calendars/&lt;CALENDARID&gt;/events?key={YOUR_API_KEY}
  Authorization:  Bearer ya29.BwGoAyc8yqYGzDz3FEPn-_zYU_EFLy0hiQzbv1h9zOnzlJe4dw1q68WNLuW7weJKNjtYYcy3P_AbsA
  X-JavaScript-User-Agent:  Google APIs Explorer
  </code></pre>
    
    <p>I'm pretty sure I'm using the same request but I'm getting error code
    403 Forbidden?</p>
    
    <p>[1]: <a href="https://stackoverflow.com/a/21987075/3583980">https://stackoverflow.com/a/21987075/3583980</a>   [2]:
    <a href="https://developers.google.com/google-apps/calendar/v3/reference/events/list" rel="nofollow noreferrer">https://developers.google.com/google-apps/calendar/v3/reference/events/list</a></p>
  </blockquote>