我有一個託管在Google App Engine上的Python Facebook項目,並使用下面的代碼來處理使用PyFacebook的Facebook API的初始化。使用PyFacebook和Google App Engine循環重定向
# Facebook Initialization
def initialize_facebook(f):
# Redirection handler
def redirect(self, url):
logger.info('Redirecting the user to: ' + url)
self.response.headers.add_header("Cache-Control", "max-age=0")
self.response.headers.add_header("Pragma", "no-cache")
self.response.out.write('<html><head><script>parent.location.replace(\'' + url + '\');</script></head></html>')
return 'Moved temporarily'
auth_token = request.params.get('auth_token', None)
fbapi = Facebook(settings['FACEBOOK_API_KEY'], settings['FACEBOOK_SECRET_KEY'], auth_token=auth_token)
if not fbapi:
logger.error('Facebook failed to initialize')
if fbapi.check_session(request) or auth_token:
pass
else:
logger.info('User not logged into Facebook')
return lambda a: redirect(a, fbapi.get_login_url())
if fbapi.added:
pass
else:
logger.info('User does not have ' + settings['FACEBOOK_APP_NAME'] + ' added')
return lambda a: redirect(a, fbapi.get_add_url())
# Return the validated API
logger.info('Facebook successfully initialized')
return lambda a: f(a, fbapi=fbapi)
我試圖設定,讓我可以在任何頁面處理方法丟棄這個裝飾,並驗證用戶的一切設置正確。問題是,當重定向處理程序被調用時,它會啓動無限循環的重定向。
我嘗試使用HTTP 302重定向來代替JavaScript,但仍然失敗。有誰知道我能做些什麼來解決這個問題?
我看到這個similar question但沒有答案。
您是否將裝飾器應用於要重定向到的頁面的處理程序? – mikerobi 2010-03-05 18:55:38
它不適用於目標頁面。目標頁面應來自由Facebook生成的頁面get_xxx_url()調用。 – 2010-03-08 14:31:10