Python的 - Facebook的API - 需要一个工作示例(Python - Faceb

2019-06-26 08:18发布

好了,我在这里用Google搜索的时候,我已经找到线程在计算器和我检查的官方Facebook和维基..和什么不..

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

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"

“所有的”我想,是找回我的好友列表现在,如果有一个更好的API点我在正确的方向,但Facebook已经正式宣布自己的Python SDK死pyfacebook几乎是为我工作,但不是很..

所以,请大家帮忙。

Answer 1:

在Python SDK一样的非官方叉仍在工作对我罚款。

:要检索你的朋友,在这里生成一个访问令牌https://developers.facebook.com/tools/access_token/

限制:

  • 与user_friends权限的用户访问令牌需要查看当前人的朋友。
  • 这只会返回谁使用(通过Facebook登录)的应用程序提出请求的任何朋友。
  • 如果这个人的朋友谢绝user_friends许可,那朋友也不会在这个人的好友列表中显示出来。

 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 - Need a working example