我想爲Gdata身份驗證拉取身份驗證令牌,以便我可以寫入Google日曆。我在驗證後獲取令牌時遇到問題,因此我可以將令牌發送到日曆服務。在App Engine上進行身份驗證後,無法獲得GData的身份驗證令牌
我使用appengine(/ _ah/login)提供的默認登錄屏幕,但我能夠登錄並進行身份驗證,但是我無法將Auth令牌拉出self.request.uri,因爲URL被改寫:
例子:
登錄屏幕從kiddushfund.appspot.com/admin重定向 https://www.google.com/accounts/ServiceLogin?service=ah&continue=http://appname.appspot.com/_ah/login%3Fcontinue%3Dhttp://appname.appspot.com/admin<mpl=gm&ahname=App+Name&sig=65e70293a754da54fe06ecbedbb59213
這是在認證之後進行最後的網址,但我不能拉令牌了 http://appname.appspot.com/admin
這似乎是一個很簡單的問題,任何幫助,將不勝感激。謝謝。
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()
感謝您的澄清,並指出我在正確的方向。 我發現適用於我的解決方案是http://code.google.com/apis/gdata/docs/auth/clientlogin.html 解決方案是調用client.ClientLogin(電子郵件,密碼,我調用gdata.calendar.service.CalendarService() – 2010-01-20 17:11:44
之後,雖然可以使用clientlogin方法,但有些用戶會對提供用戶名和密碼持謹慎態度。如果他們更改密碼或電子郵件地址,則需要再次提出要求。但是,如果您使用oauth或authsub方法,則根據我的理解,如果他們更改了用戶名和密碼,則無需詢問用戶名和密碼。需要考慮是否需要反覆訪問gdata API。 – dar 2010-01-20 18:16:31