App-engine-patch and pyFacebook not working

I am trying to write a facebook application using app-engine-patch and pyFacebook. I use only the examples provided with each tool, and for some reason it will not work.

I combined the two, as described in the accepted ansvet here: Facebook, Django and Google App Engine

app-engine-patch works fine, but when I try to use @ facebook.require_login (), I get this from GAE 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 happens no matter what kind I decorate with @ facebook.require_login ()

I am using the latest of both projects and I have no idea why this is not working.

Thanks so much for your time.

UPDATE: I made quickfix for pyFacebook, but I just forgot to return it to the stream.

Now also the 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']) 

For this:

  if params.get('expires'): if params['expires'] == 'None': params['expires'] = 0 self.session_key_expires = int(params['expires']) 

It will work, but it will hack, and perhaps it can be done more elegantly, but it works. Should point pyFacebook developers to this topic, maybe they will have a better solution.

+4
source share
2 answers

If you change facebook / __ init__.py line 1292+ from this:

  if params.get('expires'): self.session_key_expires = int(params['expires']) 

For this:

  if params.get('expires'): if params['expires'] == 'None': params['expires'] = 0 self.session_key_expires = int(params['expires']) 

It will work, but it’s a hack, and perhaps it can be done more elegantly, but it works.

+1
source

You should not use the pyfacebook @facebook.require_login() decorator when using pyfacebook with facebook-connect. The decorator is intended to be used in the facebook application because it redirects the user to the facebook site if he is not logged in, but you really want to redirect the user to your login page to your site if they are not logged in.

To verify that someone is logged in using facebook-connect and pyfacebook with djangofb middleware, you call request.fb.check_session(request) . If check_session returns True, then they have a valid session. If it returns False, you need to redirect the user to your login page so that they can click the facebook login button that you (should) have posted on this page.

+1
source

All Articles