Python的 - Facebook的API - 需要一个工作示例 [英] Python - Facebook API - Need a working example

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

问题描述

好了,我GOOGLE了四周,我发现这里的线程在计算器和我检查的官方Facebook和维基..和什么不可以。

现在我希望你们中的一个坐落在一个Facebook API示例code为Python。
这是我到目前为止已经得到了所有我得到的是无效的签名通过PyFacebook这似乎是一个死的项目:

 从Facebook导入Facebook的API_KEY ='123456789______
秘密='<正确的密钥>'
https://www.facebook.com/$c$c_gen.php?v=1.0&api_key=123456789______: - ;翁诗杰='XXXXX'#&LT从你这得到
long_term_key =无FB = Facebook的(API_KEY,秘密)高清generate_session_from_onetime_ code(FB,code):
    fb.auth_token = code
    返回fb.auth.getSession()
如果没有long_term_key:
    long_term_key = generate_session_from_onetime_ code(FB,OTK)['session_key可以']
    打印在long_term_key的.py文件替换无本:
    打印long_term_keyfb.session_key = long_term_key
fb.uid = 000000001#< - 你的用户ID
fb.signature = API_KEY#< - 这并不是在所有的工作,什么MD5?
#fb.validate_signature(FB)#< - 也不管用,概率需要通过MD5处理?
打印fb.friends.get()#< - 生成无效的签名

所有,我想,就是要找回我的好友名​​单,现在,
如果有一个更好的API点我在正确的方向,但Facebook已经正式宣布自己的Python SDK死pyfacebook几乎是为我工作,但并不完全。

所以,请大家帮帮忙。


解决方案

的href=\"https://github.com/pythonforfacebook/facebook-sdk\">非官方的叉仍工作对我罚款。

要找回你的朋友,这里的令牌生成访问:
<一href=\"https://developers.facebook.com/tools/access_token/\">https://developers.facebook.com/tools/access_token/

限制:


  • 与user_friends权限的用户访问令牌才能查看
    当前人的朋友。

  • 这只会返回谁使用(通过Facebook登录)应用程序提出请求的任何朋友。

  • 如果此人的朋友谢绝user_friends许可,那朋友也不会在这个人的好友列表中显示出来。

code


 进口的Facebook令牌='令牌'图= facebook.GraphAPI(令牌)
简介= graph.get_object(我)
朋友= graph.get_connections(我,朋友)FRIEND_LIST = [在朋友的朋友['名']的朋友['数据']打印FRIEND_LIST


Ok, so i've googled around, i've found threads here on stackoverflow and i've checked the official Facebook wiki and.. and what not..

I now hope that one of you guys sits on a Facebook API sample code for Python. This is what i've got so far and all i get is "Invalid Signature" via PyFacebook which appears to be a dead project:

from facebook import Facebook

api_key = '123456789______'
secret  = '<proper secret key>'
OTK = 'XXXXX' # <-- You get this from: https://www.facebook.com/code_gen.php?v=1.0&api_key=123456789______
long_term_key = None

fb = Facebook(api_key, secret)

def generate_session_from_onetime_code(fb, code):
    fb.auth_token = code
    return fb.auth.getSession()
if not long_term_key:
    long_term_key = generate_session_from_onetime_code(fb, OTK)['session_key']
    print 'Replace None with this in the .py file for long_term_key:'
    print long_term_key

fb.session_key = long_term_key
fb.uid = 000000001  # <-- Your user-id
fb.signature = api_key # <-- This doesn't work at all, MD5 of what?
#fb.validate_signature(fb) # <-- doesn't work either, prob need to pass MD5 handle?
print fb.friends.get() # <-- Generates "Invalid Signature"

"all" i want, is to retrieve my friends list for now, if there's a better API point me in the right direction but Facebook has officially declared their own Python SDK dead and pyfacebook is almost working for me but not quite..

So, please help.

解决方案

The unofficial fork of the python sdk is still working fine for me.

To retrieve your friends, generate an access token here: https://developers.facebook.com/tools/access_token/

Limitations:

  • A user access token with user_friends permission is required to view the current person's friends.
  • This will only return any friends who have used (via Facebook Login) the app making the request.
  • If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.

Code

import facebook

token = 'your token'

graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")

friend_list = [friend['name'] for friend in friends['data']]

print friend_list

这篇关于Python的 - Facebook的API - 需要一个工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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