Facebook Graph API 使用哪个 Django 库?
我目前正在 Django 中开发一个应用程序,并尝试实现 Facebook 身份验证和对 Graph API 的请求。我见过一些不同的库,但执行以下操作的最佳方法是什么:
- 让用户通过 Facebook 登录。
- Django 为他们创建一个新用户并添加他们的 uid 和 oauth 令牌。
- 然后我可以使用 Facebook 的 Python SDK 调用 Graph API。
我确实看到了这个示例。普通的 Django 就这么简单吗?
I'm currently developing an application in Django and trying to implement Facebook authentication and requests to the Graph API. I've seen a few different libraries out there, but what is the best way to do the following:
- Have a user login via Facebook.
- Django creates a new user for them and adds their uid and oauth token.
- I can then make calls to the Graph API using Facebook's Python SDK.
I did see this example. Is it that simple on normal Django?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的公司已经构建了一个库,使将 Facebook 集成到 Django 应用程序中变得非常简单(我们可能已经使用该库构建了 10-20 个应用程序,其中包括一些具有大量流量的应用程序,因此它已经过实际测试)。
在您的设置中,添加
FACEBOOK_KEY
、FACEBOOK_SECRET
、FACEBOOK_SCOPE
、FACEBOOK_REDIRECT_URL
和PRIMARY_USER_MODEL< 的值/代码>。您还需要将
ecl_facebook.backends.FacebookAuthBackend
添加到AUTHENTICATION_BACKENDS
中。例如,在 settings.py 中:在 views.py 中添加一些视图来处理身份验证前和身份验证后逻辑。
现在只需将这些 URL 连接到您的 urls.py 文件中即可。
希望这有帮助!
PS 您可以在此处阅读文档的其余部分。
My company has built a library that makes integrating Facebook into your Django application dead simple (we've probably built 10-20 apps with the library, including some with huge amounts of traffic, so it's been battle-tested).
In your settings, add values for your
FACEBOOK_KEY
,FACEBOOK_SECRET
,FACEBOOK_SCOPE
,FACEBOOK_REDIRECT_URL
, andPRIMARY_USER_MODEL
. You'll also need to addecl_facebook.backends.FacebookAuthBackend
to yourAUTHENTICATION_BACKENDS
. For example, in settings.py:Add some views in your views.py to handle pre- and post-authentication logic.
Now just hook up these URLs in your urls.py file and you're done.
Hope this helps!
P.S. You can read the rest of the docs here.
我们在我工作的地方进行了大量 Facebook 应用程序开发,因此我们开发了一个开源库这使得一切变得非常简单。
We do a lot of Facebook Application development where I work, and so we've developed an open-source library that makes everything about it really easy.
我推荐 https://github.com/egnity/fb.py。我的基于 Django 的 Facebook 应用程序很快就启动并运行了。它包含一个中间件,允许您在视图中运行如下代码:
for the user id:
for the oauth token:
然后您可以根据需要将上述内容添加到您的 User 模型中。要进行 Graph API 调用,您仍然可以使用 fb.py 的中间件——无需使用原始 python-sdk。上面的 user_id 代码是 Graph API 调用的完美示例。使用 fb.py 您还可以做更多事情。下载包含一个示例 django 项目,可帮助您入门。
I recommend https://github.com/egnity/fb.py. Got my Django-based Facebook app up and running in no time. It includes a middleware that allows you to run code like this in your view:
for the user id:
for the oauth token:
You can then add the above to your User model as you please. To make Graph API calls, you can still use fb.py's middleware -- no need for using the primitive python-sdk. The user_id code above is a perfect example of a Graph API call. There's much more you can do with fb.py. The download includes a sample django project to get you going.