python抓fb留言 - Python-Facebook API-需要一個有效的例子
python facebook發文 (1)
好的,所以我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"
“所有”我想要的,就是現在檢索我的朋友列表,如果有更好的API指向我正確的方向但Facebook已經正式宣布他們自己的Python SDK死了,pyfacebook幾乎為我工作但不完全..
所以,請幫忙。
python sdk的非官方分支對我來說仍然很好。
要檢索您的朋友,請在此處生成訪問令牌: https://developers.facebook.com/tools/access_token/ : 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