I am trying to write a facebook app using app-engine-patch and pyFacebook. I am using nothing but the examples provided with each tool and for some reason it will not work.
I have combined the two just as described in the accepted answet here: Facebook, Django, and Google App Engine
app-engine-patch seems to work just fine but when I try to use @facebook.require_login() I get this from GAE's logs:
Exception in request:
Traceback (most recent call last):
File "/base/data/home/apps/app-name/1.339079629847560090/common/zip-packages/django-1.1.zip/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/base/data/home/apps/app-name/1.339079629847560090/facebook/djangofb/__init__.py", line 87, in newview
if not fb.check_session(request):
File "/base/data/home/apps/app-name/1.339079629847560090/facebook/__init__.py", line 1293, in check_session
self.session_key_expires = int(params['expires'])
ValueError: invalid literal for int() with base 10: 'None'
This happends no matter which view I decorate with @facebook.require_login()
I am using the latest from both projects and I have no idea why it wont work.
Many thanks for your time.
UPDATE: I made a quickfix for pyFacebook, but I just forgot to put it back in the thread.
Now also as an answer, since it seems to be the only way.
If you change facebook/__init__.py line 1292+ from this:
if params.get('expires'):
self.session_key_expires = int(params['expires'])
To this:
if params.get('expires'):
if params['expires'] == 'None':
params['expires'] = 0
self.session_key_expires = int(params['expires'])
It will wo开发者_Python百科rk, but it is a hack and maybe it could be done more elegantly, but it works. Gotta point the pyFacebook devs to this thread, maybe they will have a better solution.
You should not use pyfacebook's decorator @facebook.require_login()
when using pyfacebook with facebook-connect. The decorator is meant to be used for a facebook application, as it redirects the user to the facebook site if they are not logged in, but you really want to redirect the user to your login page on your site if they are not logged in.
To check if someone is logged in with facebook-connect and pyfacebook with the djangofb middleware, you call request.fb.check_session(request)
. If check_session
returns True then they have a valid session. If it returns False then you need to redirect the user to your login page so they can click the facebook connect login button you (should) have placed on that page.
If you change facebook/__init__.py line 1292+ from this:
if params.get('expires'):
self.session_key_expires = int(params['expires'])
To this:
if params.get('expires'):
if params['expires'] == 'None':
params['expires'] = 0
self.session_key_expires = int(params['expires'])
It will work, but it is a hack and maybe it could be done more elegantly, but it works.
精彩评论