Python 在App Engine上进行身份验证后,无法获取GData的身份验证令牌

Python 在App Engine上进行身份验证后,无法获取GData的身份验证令牌,python,google-app-engine,gdata-api,gdata,google-data-api,Python,Google App Engine,Gdata Api,Gdata,Google Data Api,我想为gdataauth提取Auth令牌,这样我就可以写入谷歌日历。我在身份验证后获取令牌时遇到问题,因此我无法将令牌发送到日历服务 我正在使用appengine(/_ah/login)提供的默认登录屏幕,并且我能够登录和验证,但是,我无法从self.request.uri中提取身份验证令牌,因为URL正在重写: 例如: 从kiddushfund.appspot.com/admin重定向登录屏幕 这是在身份验证之后,URL已从firebug中拉出 这是身份验证后的最终URL,但我无法再提取令

我想为gdataauth提取Auth令牌,这样我就可以写入谷歌日历。我在身份验证后获取令牌时遇到问题,因此我无法将令牌发送到日历服务

我正在使用appengine(/_ah/login)提供的默认登录屏幕,并且我能够登录和验证,但是,我无法从self.request.uri中提取身份验证令牌,因为URL正在重写:

例如:

从kiddushfund.appspot.com/admin重定向登录屏幕

这是在身份验证之后,URL已从firebug中拉出

这是身份验证后的最终URL,但我无法再提取令牌了

这似乎是一个非常简单的问题,任何帮助都将不胜感激。谢谢

from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
from google.appengine.ext import webapp

import atom
import settings
import os
import urllib
import urllib2
import cookielib

import gdata.service
import gdata.auth
import gdata.alt.appengine
import gdata.calendar
import gdata.calendar.service


class Auth(webapp.RequestHandler):
    def __init__(self):
        self.calendar_client = gdata.calendar.service.CalendarService()
        gdata.alt.appengine.run_on_appengine(self.calendar_client)

def get(self):
    user = users.get_current_user()
    if user:
        token_request_url = None
        auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)

        if auth_token:
            self.calendar_client.SetAuthSubToken(self.calendar_client.upgrade_to_session_token(auth_token))

        if not isinstance(self.calendar_client.token_store.find_token(
                'http://www.google.com/calendar/feeds/'),gdata.auth.AuthSubToken):
                token_request_url = gdata.auth.generate_auth_sub_url(self.request.uri,
                ('http://www.google.com/calendar/feeds/default/',))

        #This is where I were I would look for the token but the self.request.url
        # is only return http://appname.appspot.admin - with no token.  
        self.response.out.write(self.request.uri)

    else:
        self.redirect(users.create_login_url(self.request.uri))



def main():
    application = webapp.WSGIApplication([('/.*', Auth),], debug=True)
    run_wsgi_app(application)

if __name__ == '__main__':
    main()

登录屏幕仅向您的应用程序验证用户,而不授予您对用户gdata的授权

您需要让用户授权您使用日历api-我建议通过oauth在此处:


您只需要执行一次,然后为该用户存储oauth令牌以用于所有后续调用

登录屏幕仅向您的应用程序验证用户,而不授予您对用户gdata的授权

您需要让用户授权您使用日历api-我建议通过oauth在此处:


您只需要执行一次,然后为该用户存储oauth令牌以用于所有后续调用

未完成令牌的数量存在限制,例如可能的用户数量。未完成的ClientLogin令牌数量如何?

未完成的令牌数量有限制,例如可能的用户数量。有多少ClientLogin代币尚未使用?

感谢您的澄清,并为我指明了正确的方向。我发现对我有效的解决方案是在我调用gdata.calendar.service.CalendarService()之后调用client.ClientLogin(电子邮件,密码,source=application\u name),虽然当然可以使用ClientLogin方法,但有些用户会担心给你他们的用户名和密码。如果他们更改了密码或电子邮件地址,您需要再次询问。但是如果您使用oauth或authsub方法,您不需要询问用户名和密码,如果他们按照我的理解更改了用户名和密码。如果您需要重复访问GDATAPI,请考虑一下,谢谢您的澄清,并指出了我的正确方向。我发现对我有效的解决方案是在我调用gdata.calendar.service.CalendarService()之后调用client.ClientLogin(电子邮件,密码,source=application\u name),虽然当然可以使用ClientLogin方法,但有些用户会担心给你他们的用户名和密码。如果他们更改了密码或电子邮件地址,您需要再次询问。但是如果您使用oauth或authsub方法,您不需要询问用户名和密码,如果他们按照我的理解更改了用户名和密码。如果需要重复访问GDATA API,需要考虑一些问题。