4

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 work, 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.

Community
  • 1
  • 1
Mathias Nielsen
  • 1,560
  • 1
  • 17
  • 31
  • I'm having the same problem. Where in the directory structure of the sample AEP application did you put the PyFacebook stuff? – Bialecki Jan 11 '10 at 02:42
  • Oh btw, the reason this happens is because a browser cookie, which the Facebook code expects to be None is set to the string, "None" and then tries to get parsed. I don't know why that cookie is set or what the bug is, put that's why it happens. You'll find if you clear your cookies, then hit your site, it'll suddenly redirect to Facebook. That doesn't solve the problem, but it's a little more info. – Bialecki Jan 11 '10 at 02:45
  • I put the facebook dir in the root of the AEP-sample dir. Just as described in the link and they seemed to be able to make it work. Thanks for the tip with the cookie, will try to tinker a little with it. – Mathias Nielsen Jan 11 '10 at 14:17

2 Answers2

1

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.

dar
  • 6,520
  • 7
  • 33
  • 44
  • Well I am using it to make a facebook-app, but I am using the IFrame setting so I guess it just behaves as a facebook-connect site? – Mathias Nielsen Jan 11 '10 at 14:13
1

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.

Mathias Nielsen
  • 1,560
  • 1
  • 17
  • 31