The \"old\" Facebook Graph API had a \"username\" field which could be used to create a human-readable profile URL. My username for example is \"sebastian.trug\" which resul
Inspired from @RifkiFauzi 's answer, here is my solution in pure Python
#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)
While the 2.0 SDK will not provide the username
field any longer, it is quite easily scraped if you have the user id number (which you will likely be using to access the graph anyway).
The url facebook.com/<user id>
will redirect to facebook.com/<username>
, which can then be extracted however you like.