Hi all...

 I have been studying several examples trying to get my first
AppEngine app to work with the Google Calendar API.    I am trying to
understand why my code isn't working GDataService vs CalendarService

I would like a clean elegant interface and the CalendarService seems
cleaner but the token upgrade fails.

What's the difference and how should I be doing this?

--------begin works-----------
     feed=''http://www.google.com/calendar/feeds/default/owncalendars/
full'
     fetcher = Fetcher()
     client = fetcher.GetClient(self, feed)
     calendars = client.Get(feed, converter=str)

class Fetcher():
def GetClient(self, handler, scope):
    user = users.get_current_user()
    if user:
      client = gdata.service.GDataService()
      gdata.alt.appengine.run_on_appengine(client)
      for token in StoredToken.gql('WHERE user_email = :1', user.email
()):
        if scope.find(token.target_url) > -1:
           client.SetAuthSubToken(token.session_token)
           return client
      if handler.request.get('token'):
        token = handler.request.get('token')
        if handler.request.get('auth_sub_scopes'):
            scope = handler.request.get('auth_sub_scopes')
        client.SetAuthSubToken(token)
        client.UpgradeToSessionToken()
        new_token = StoredToken(user_email=user.email(),
                                session_token=client.GetAuthSubToken
(),
                                target_url=scope)
        new_token.put()
        return client
      else:
          handler.redirect(client.GenerateAuthSubURL
(handler.request.uri,
                                             scope,
                                             secure=False,
                                             session=True).to_string
())
    else:
      handler.redirect(users.create_login_url(handler.request.uri))

--------end works-----------

The following breaks and fails with:

TokenUpgradeFailed: {'status': 403, 'body': '<HTML>\n<HEAD>
\n<TITLE>Attempt to upgrade a non-upgradeable token</TITLE>\n...

--------begin broke-----------

     feed=''http://www.google.com/calendar/feeds/default/owncalendars/
full'
     fetcher = Fetcher()
     calClient = fetcher.GetCalendarClient(self, feed)
     calendars = calClient.GetCalendarListFeed()

class Fetcher():
  def GetCalendarClient(self, handler, scope):
    user = users.get_current_user()
    if user:
      client = gdata.calendar.service.CalendarService()
      gdata.alt.appengine.run_on_appengine(client)
      for token in StoredToken.gql('WHERE user_email = :1', user.email
()):
        if scope.find(token.target_url) > -1:
           client.SetAuthSubToken(token.session_token)
           return client
      if handler.request.get('token'):
        token = handler.request.get('token')
        if handler.request.get('auth_sub_scopes'):
            scope = handler.request.get('auth_sub_scopes')
        client.auth_token = token
        #client.SetAuthSubToken(token)
        client.UpgradeToSessionToken()
        new_token = StoredToken(user_email=user.email(),
                                session_token=client.GetAuthSubToken
(),
                                target_url=scope)
        new_token.put()
        return client
      else:
          handler.redirect(client.GenerateAuthSubURL
(handler.request.uri,
                                             scope,
                                             secure=False,
                                             session=True).to_string
())
    else:
      handler.redirect(users.create_login_url(handler.request.uri)

--------end broke-----------

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to