由于用户名是没有更多的可以从图形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