Aug 19, 2015

f Comment

How to get Facebook user profile URL given a numeric ID in SECONDS?

Amazon If you use Facebook Graph API to crawl Facebook users, the JSON data you get looks something like this:
...
"from": {
  "name": "Michael",
  "id": "100000123456"
},
...
The key "id" points to the FB user's identifier. Given this identifier you can construct a URL that points to the user's Facebook main profile. However, one day you realize this issue: there are two IDs for the same person! How is that possible? How do you get the Facebook user's profile URL given either ID?

[Update per 2015/12/18] It looks like if the FB user has no user name, then you can use either https://www.facebook.com/profile.php?id=<id> or https://www.facebook.com/app_scoped_user_id/<id>/. If the FB user has user name, then you use https://www.facebook.com/app_scoped_user_id/<id>/ (e.g. https://www.facebook.com/app_scoped_user_id/3624019/).

Getting Facebook user URL by ID is easy. Read on to see how.

Cause

The cause of having more than one ID for the same FB user is due to their software upgrade. Facebook has introduced the concept of "app scoped user ID". You can find more information at FB's official documentation page.

Solution

The solution is easy. Simply try the following URLs (replace <id> with the actual ID):
http://facebook.com/profile.php?id=<ID>
https://www.facebook.com/app_scoped_user_id/<ID>
For example, if the ID is 100000123456, then here are the URLs to try:
http://facebook.com/profile.php?id=100000123456
https://www.facebook.com/app_scoped_user_id/100000123456
And one of them should redirect you to the Facebook user's profile URL, which looks like this:
https://www.facebook.com/feedthehungry
Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael