Python - Facebook API - 需要一个有效的例子

Tor*_*xed 40 python api facebook signature pyfacebook

好吧,所以我google了一下,我在stackoverflow上找到了线程,我已经检查了官方的Facebook wiki和..什么不是..

我现在希望你们其中一个人坐在用于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"
Run Code Online (Sandbox Code Playgroud)

"所有"我想要的,就是现在检索我的朋友列表,如果有更好的API指向我正确的方向但Facebook已经正式宣布他们自己的Python SDK死了,pyfacebook几乎为我工作但不完全..

所以,请帮忙.

dom*_*dom 69

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
Run Code Online (Sandbox Code Playgroud)

  • 这肯定已经改变,因为我只得到'{'data':[],'summary':{'total_count':712}}`在`friend_list`中返回 (4认同)
  • 它被称为分页结果,这是他们在发布此问题后开始的.每个搜索结果都是"分页",意味着你得到的结果是250的10000,接下来是101-200,接下来的是201-250. (3认同)