Facebook API和Python [英] Facebook API and Python

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

问题描述

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



官方的 Facebook Python SDK 与Google App Engine绑定, Pyfacebook 与Django深深编织。



我只是希望能够在终端中混乱,并通过验证用户的过程,然后从Facebook API中做简单的请求。



谢谢。

解决方案

我曾经遇到同样的问题,后来发现PyFacebook与Django并没有很深的关系。它只是使用django的几个工具。



我的建议是,您设置PyFacebook与django,然后使用命令行玩。要使用PyFacebook,您根本不需要经历甚至知道任何关于django的信息。



这里有一个例子:

 从Facebook导入Facebook 

api_key ='您的App API密钥'
secret ='您的应用密钥'

session_key ='你的无限会话密钥的用户'

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

#现在使用fb对象玩

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



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

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


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

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

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.

Thanks.

解决方案

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.

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.

Here's an example:

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

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

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天全站免登陆