问题描述
好的,所以我在谷歌上搜索了一下,我在 stackoverflow 上找到了相关主题,我还查看了官方 Facebook wiki 和.. 还有什么没有..
我现在希望你们中的一个人坐在 Facebook 的 Python API 示例代码上.这是我到目前为止所得到的,我得到的只是通过 PyFacebook 获得的无效签名",这似乎是一个死项目:
从脸书导入脸书api_key = '123456789______'secret = ''OTK = 'XXXXX' # <-- 你从:https://www.facebook.com/code_gen.php?v=1.0&api_key=123456789______long_term_key = 无fb = Facebook(api_key,秘密)def generate_session_from_onetime_code(fb, code):fb.auth_token = 代码返回 fb.auth.getSession()如果不是 long_term_key:long_term_key = generate_session_from_onetime_code(fb, OTK)['session_key']打印 '在 long_term_key 的 .py 文件中用这个替换 None:'打印 long_term_keyfb.session_key = long_term_keyfb.uid = 000000001 # <-- 您的用户 IDfb.signature = api_key # <-- 这根本行不通,什么 MD5?#fb.validate_signature(fb) # <-- 也不起作用,可能需要通过 MD5 句柄吗?打印 fb.friends.get() # <-- 生成无效签名"
我想要的全部"是暂时检索我的朋友列表,如果有更好的 API 会指出我正确的方向,但 Facebook 已正式宣布他们自己的 Python SDK 已死,而 pyfacebook 几乎对我有用,但并不完全......
所以,请帮忙.
python sdk 的非官方分支仍然存在对我来说很好.
要检索您的朋友,请在此处生成访问令牌:https://developers.facebook.com/tools/access_token/
限制:
- 需要具有 user_friends 权限的用户访问令牌才能查看当前人的朋友.
- 这只会返回使用(通过 Facebook 登录)发出请求的应用的所有朋友.
- 如果此人的好友拒绝了 user_friends 权限,该好友将不会出现在此人的好友列表中.
代码
导入脸书令牌 = '你的令牌'图 = facebook.GraphAPI(令牌)profile = graph.get_object("我")朋友 = graph.get_connections("我","朋友")friend_list = [friend['name'] 为朋友中的朋友['data']]打印朋友列表
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 viewthe 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
这篇关于Python - Facebook API - 需要一个工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!