How does one avoid a cyclic redirect when writing a facebook application using pyfacebook and google app engine?

百般思念 提交于 2019-12-08 03:02:09

问题


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.


回答1:


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.




回答2:


I agree with cope360. I've been playing around with facebook app development for a little while now. They seem to be changing their API frequently, so you'd be better off using the official libraries.

That said, to answer your question, pyfacebbok tries to get authenticaion information from information in django's HttpRequest.GET. This is out-dated, because facebook provides authenticaion info in POST data.

The source code that's responsible is in pyfacebook/facebook/__init__.py. The method name seems to be validate_request.



来源:https://stackoverflow.com/questions/1116314/how-does-one-avoid-a-cyclic-redirect-when-writing-a-facebook-application-using-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!