Facebook API 和 Python [英] Facebook API and Python

查看:16
本文介绍了Facebook API 和 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道通过 Python 进行 Facebook 身份验证和 Graph API 访问的良好的平台无关示例或库?

Does anyone know of a good platform agnostic example or library that does Facebook authentication and Graph API access via Python?

官方 Facebook Python SDK 绑定到 Google App Engine 和 Pyfacebook 与 Django 紧密相连.

The official Facebook Python SDK is tied to Google App Engine and Pyfacebook is deeply woven with Django.

我只是希望能够在终端中进行操作并完成对用户进行身份验证的过程,然后从 Facebook API 执行简单的请求.

I just want to be able to mess around in terminal and go through the process of authenticating a user and then doing simple requests from the Facebook API.

谢谢.

推荐答案

我前段时间遇到了同样的问题,后来发现 PyFacebook 与 Django 并没有很深的联系.它只使用了 django 中的一些实用程序.

I ran across same problem some time ago and later found out that PyFacebook isn't deeply tied up with Django. It just uses a few utils from django.

我的建议是,您将 PyFacebook 与 django 一起设置,然后使用命令行来玩弄它.要使用 PyFacebook,您根本无需了解甚至对 django 一无所知.

My recommendation is that you setup PyFacebook alongwith django and then play around with it using command line. To use PyFacebook you won't have to go through or even know anything about django at all.

这是一个例子:

from facebook import Facebook

api_key = 'Your App API Key'
secret  = 'Your App Secret Key'

session_key = 'your infinite Session key of user'

fb = Facebook(api_key, secret)
fb.session_key = session_key

# now use the fb object for playing around

您可能需要从这里获取无限会话密钥:http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY

You might need to get an infinite session key which you can get from here: http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY

使用此代码将上述 URL 中的代码转换为无限会话密钥:

Use this code to get convert the code from above URL into infinite session key:

def generate_session_from_onetime_code(fb, code):
    fb.auth_token = code
    return fb.auth.getSession()
print generate_session_from_onetime_code(fb, session_onetime_code)

这篇关于Facebook API 和 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆