Convert Facebook names to id numbers

Ivelius picture Ivelius · Jan 5, 2012 · Viewed 29.2k times · Source

I've noticed some difference in Facebook profiles :

Some of them have the following string format at browser nav bar :

http://facebook.com/john.smith

and the others look like this : http://www.facebook.com/profile.php?id=100455*

Can someone explain why there is a difference ?

And more important is how can I convert those john.smith like names to id numbers ?

Answer

nav picture nav · Jan 5, 2012

These are alias urls that Facebook offers its users (and pages) - its basically a vanity thing, both the id and the alias url will work the same way.

You can translate the alias (or username) by doing a lookup for that user using the Facebook Graph API. Simply make a GET request to https://graph.facebook.com/John for example - this will serve the following response:

{
  "id": "779695190",
  "name": "John Chan",
  "first_name": "John",
  "last_name": "Chan",
  "link": "http://www.facebook.com/John",
  "username": "John",
  "gender": "male",
  "locale": "en_US",
  "updated_time": "2011-12-27T05:01:06+0000",
  "type": "user"
}

response.id is what your interested in.

Test it out: http://developers.facebook.com/tools/explorer?method=GET&path=john