views:

386

answers:

1

Hello. I'm trying to write my first application for Facebook using python and pyfacebook hosted on Google App Engine. The problem I'm facing is that of cyclic redirects. Firefox dies complaining "This page isn't redirecting properly" when I visit http://apps.facebook.com/appname.

Here's the code:

class CanvasHandler(webapp.RequestHandler):
    def get(self):
        ## instantiate the Facebook API wrapper with your FB App's keys
        fb = facebook.Facebook(config.FACEBOOK_API_KEY, config.FACEBOOK_API_SECRET)

        ## check that the user is logged into FB and has added the app
        ## otherwise redirect to where the user can login and install
        if fb.check_session(self.request) and fb.added:
            pass
        else:
           url = fb.get_add_url()
           self.response.out.write('<script language="javascript">top.location.href="' + url + '";</script>')
           return

        rendered_template = render_template('facebook/app.html')
        self.response.out.write(rendered_template)

I see this problem when I'm logged out of Facebook. Any help is appreciated.

A: 

If you're just starting out with your Facebook app, consider using the Official Python SDK which accesses the Graph API. The REST API is being phased out.

To do authentication, use the JS SDK which will set a cookie you can read on the server side.

cope360