Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Facebook names to id numbers

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 ?

like image 709
Ivelius Avatar asked Dec 28 '22 08:12

Ivelius


2 Answers

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

like image 189
nav Avatar answered Jan 20 '23 18:01

nav


You're not really want to converting the ids to names but getting id by username which is possible by issuing request to Graph API:

GET https:/graph.facebook.com/john.smith?fields=id
like image 24
Juicy Scripter Avatar answered Jan 20 '23 17:01

Juicy Scripter