Ivelius
Ivelius

Reputation: 5013

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 ?

Upvotes: 4

Views: 32301

Answers (3)

Zorayr
Zorayr

Reputation: 24922

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);
    }
});

Upvotes: 0

Juicy Scripter
Juicy Scripter

Reputation: 25918

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

Upvotes: 1

nav
nav

Reputation: 3115

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

Upvotes: 9

Related Questions