使用 pyfacebook 和 google 应用引擎编写 Facebook 应用程序时如何避免循环重定向?
我正在尝试使用 Facebook 编写我的第一个应用程序 python 和 pyfacebook 托管在 Google App Engine 上。 我面临的问题是 循环重定向。 Firefox 死后抱怨“此页面不是 当我访问 http://apps.facebook.com/appname 时,“正确重定向”。
代码如下:
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)
当我退出 Facebook 时,我看到了这个问题。如有任何帮助,我们将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您刚刚开始使用 Facebook 应用,请考虑使用官方 Python SDK访问图形 API。 REST API 正在逐步淘汰。
要进行身份验证,请使用 JS SDK,它将设置一个您可以读取的 cookie服务器端。
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的观点。 我从事 Facebook 应用程序开发已经有一段时间了。 他们似乎经常改变他们的 API,所以你最好使用官方库。
也就是说,为了回答您的问题,pyfacebbok 尝试从 django 的 HttpRequest.GET 中的信息获取身份验证信息。 这已经过时了,因为 facebook 在 POST 数据中提供身份验证信息。
负责的源代码位于 pyfacebook/facebook/__init__.py 中。 方法名称似乎是validate_request。
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.