I am getting a token upgrade failed error when i try to create a calendar reminder using google's gdata used in an appengine environment.
The code fragment is:
def InsertSingleEvent(calendar_service, title=None,
content=None, where=None,
start_time=None, end_time=None):
event = gdata.calendar.CalendarEventEntry()
event.title = atom.Title(text=title)
event.content = atom.Content(text=content)
event.where.append(gdata.calendar.Where(value_string=where))
if start_time is None:
# Use current time for the start_time and have the event last 1 hour
start_time = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime())
end_time = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.time() + 3600))
event.when.append(gdata.calendar.When(start_time=start_time, end_time=end_time))
for a_when in event.when:
if len(a_when.reminder) > 0:
a_when.reminder[0].minutes = minutes
else:
a_when.reminder.append(gdata.calendar.Reminder(hours=23))
new_event = calendar_service.InsertEvent(event, '/calendar/feeds/default/private/full')
def addreminder(request, acton_id):
"""subscribes user to an acton. Currently i don't verify if user is signed in or not
If he isn't then weirdos"""
acton = Acton.get_by_id(int(acton_id))
start_time = acton.creationTime.strftime('%Y-%m-%dT%H:%M:%S.000Z')
next_url = atom.url.Url('http', settings.HOST_NAME,
path='/sanjhachoolha/acton/%s/remind' % acton_id)
calendar_service = gdata.calendar.service.CalendarService()
gdata.alt.appengine.run_on_appengine(calendar_service,store_tokens = True, single_user_mode = True)
session_token = None
auth_token = gdata.auth.extract_auth_sub_token_from_url(request.get_full_path())
if auth_token:
v=request.get_full_path()
session_token = calendar_service.upgrade_to_session_token(auth_token)
if session_token and users.get_current_user():
calendar_service.token_store.add_token(session_token)
InsertSingleEvent(calendar_service, title=acton.title, content=acton.description,
start_time=start_time)
elif session_token:
calendar_service.current_token = session_token
assert err2
authSubUrl = calendar_service.GenerateAuthSubURL(next_url,
('http://www.google.com/calendar/feeds/',),
secure=False, session=True)
return shortcuts.render_to_response('sc-blah.html', {'authSubUrl':authSubUrl,
})
The traceback i got is:
Environment:
Request Method: GET
Request URL: http://sanjhachoolha-sandbox.appspot.com/sanjhachoolha/acton/6003/remind
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['appengine_django']
Installed Middleware:
('django.middleware.common.CommonMiddleware',)
Traceback:
File "/base/data/home/apps/sanjhachoolha-sandbox/dushyanth-1.335336048913759977/django/core/handlers/base.py" in get_response
86. response = callback(request, *callback_args, **callback_kwargs)
File "/base/data/home/apps/sanjhachoolha-sandbox/dushyanth-1.335336048913759977/sanjhachoolha/views.py" in addreminder
946. session_token = calendar_service.upgrade_to_session_token(auth_token)
File "/base/data/home/apps/sanjhachoolha-sandbox/dushyanth-1.335336048913759977/gdata/service.py" in upgrade_to_session_token
921. 'body': response_body})
Exception Type: TokenUpgradeFailed at /sanjhachoolha/acton/6003/remind
Exception Value: {'status': 403L, 'body': '<HTML>\n<HEAD>\n<TITLE>Invalid AuthSub token.</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Invalid AuthSub token.</H1>\n<H2>Error 403</H2>\n</BODY>\n</HTML>\n', 'reason': 'Non 200 response on upgrade'}
What i think is that the single use token itself is flawed. the uri for example is u'/sanjhachoolha/acton/6003/remind?auth_sub_scopes=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F&token=CL-e_pv3GxCCp723BQ'
Thanks in advance.