4

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 ?

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
Ivelius
  • 4,953
  • 7
  • 30
  • 54

3 Answers3

9

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

nav
  • 3,035
  • 1
  • 20
  • 24
  • Now I have another issue.Take a look at this link : https://graph.facebook.com/100002639486261 It's some person that wrote his name in hebrew.Is there a way to decrypt this ? – Ivelius Jan 15 '12 at 13:17
  • http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha – Joakim Syk Mar 13 '12 at 09:48
  • 2
    Note this solution is now defunct as facebook, as of just a few days ago, is requiring authentication before you can access graph.facebook.com – Steele Parker Jun 25 '15 at 01:39
1

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
Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
0

Here is a JQuery based solution, where callback is an arbitrary function:

$.get("https://graph.facebook.com/" + name + "?fields=id", function(response){
    if(response.error){
        callback(false)
    }else{
        callback(response.id);
    }
});
Zorayr
  • 23,770
  • 8
  • 136
  • 129