Facebook user url by id
UPDATE 2: This information is no more given by facebook. There is an official announcement for the behavior change (https://developers.facebook.com/blog/post/2018/04/19/facebook-login-changes-address-abuse/) but none for its alternative.
Yes, Just use this link and append your ID to the id
parameter:
https://facebook.com/profile.php?id=<UID>
So for example:
https://facebook.com/profile.php?id=4
Will redirect you automatically to https://www.facebook.com/zuck
Which is Mark Zuckerberg's profile.
If you want to do this for all your ids, then you can do it using a loop.
If you'd like, I can provide you with a snippet.
UPDATE: Alternatively, You can also do this:
https://facebook.com/<UID>
So that would be: https://facebook.com/4 which would automatically redirect to Zuck!
Accepted answer didn't work for me, this does:
https://www.facebook.com/app_scoped_user_id/10152384781676191
The easiest and the most correct (and legal) way is to use graph api.
Just perform the request: http://graph.facebook.com/4
which returns
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "http://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US"
}
and take the link
key.
You can also reduce the traffic by using fields
parameter: http://graph.facebook.com/4?fields=link to get only what you need:
{
"link": "http://www.facebook.com/zuck",
"id": "4"
}
The marked answer seems outdated and it won't work.
Facebook now only gives unique ID related to app which isn't equal to userId and profileUrl and username will come out to be empty.
Doing me?fields=id,name,links
is also depreciated after Graph Version 2.4
The only option now is to request for user_links permission from your developer console.
and the pass it in scope when doing facebook login
scope: ['user_link'] }
or by doing an api call
As of now (NOV-2019), graph.api V5.0
graph API says, refer graph api
A link to the person's Timeline. The link will only resolve if the person clicking the link is logged into Facebook and is a friend of the person whose profile is being viewed.