由於用戶名是沒有更多的可以從圖形API端點/user-id
所討論here,我在這裏提出了另一種解決方法(但與Python代碼)
簡而言之,我們在FB打開網頁.COM/USER_ID和刮的用戶名就
#get html of a page via pure python ref. https://stackoverflow.com/a/23565355/248616
import requests
r = requests.get('http://fb.com/%s' % FB_USER_ID) #open profile page of the facebook user
r.raise_for_status()
html = r.content
#search string with regex ref. https://stackoverflow.com/a/4667014/248616
import re
# m = re.search('meta http-equiv="refresh" content="0; URL=/([^?]+)\?', html)
m = re.search('a class="profileLink" href="([^"]+)"', html)
href = m.group(1) #will be https://www.facebook.com/$FB_USER_NAME on 201705.24
username = href.split('/')[-1]
print(href)
print(username)
這將停止在2015年4月30日工作時API 1.0版被刪除 – WizKid 2014-10-30 01:05:00
對於這麼簡單的任務來說,php sdk太重了,恕我直言。但答案是正確的,所以+1爲你:) – luschn 2014-10-30 08:26:25
@luschn是好點也可能是這樣一個簡單的意圖很煩瑣 – Ghost 2014-10-30 08:45:04