Get "real" profile URL from Facebook Graph API /user

34,439

Solution 1

You can´t get the real ID or the username of users anymore, so there is no way to get the "real URL". More information: https://developers.facebook.com/docs/apps/changelog

You can get a link to the user profile with the following API call though: /me?fields=link

Check out "App Scoped IDs" in the Facebook docs.

Update: It seems that linking to the user profile is not possible anymore: https://developers.facebook.com/blog/post/2018/04/19/facebook-login-changes-address-abuse/

Solution 2

It looks like Facebook has created a separate permission (which user needs to approve) called user_link for you to be able to fetch that. You can see more details here: https://developers.facebook.com/docs/facebook-login/permissions/#reference-user_link

When you query metadata about available fields for the endpoint using /me?metadata=1 this is what the link description says:

{
  "name": "link",
  "description": "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.",
  "type": "string"
}

If user has approved that permission, you will be able to fetch the link as before:

/me?fields=link

{
  "link": "https://www.facebook.com/app_scoped_user_id/SOME_TOKEN/",
  "id": "USER_ID"
}
Share:
34,439

Related videos on Youtube

jchook
Author by

jchook

Happy programmer.

Updated on October 05, 2020

Comments

  • jchook
    jchook over 3 years

    As stated in the API docs for /user, the link field contains the user's profile URL. However, this URL commonly redirects to a different URL (i.e. the one that shows up in Google results).

    Is there any way to determine the final redirect location (the "real" URL) of a given profile via the Facebook API?

    For example, given:

    "link":"https://www.facebook.com/1091552020"

    I want to retrieve https://www.facebook.com/sbhutiani from the API

    • Lejdi Prifti
      Lejdi Prifti about 9 years
      Not possible and it is by design
  • Sarah
    Sarah over 7 years
    thanks. so is there any way to link back to the person's facebook page from your app? ive seen a bit about app scoped IDs but I'm still unsure. thanks
  • andyrandy
    andyrandy over 7 years
    there you go: /me?fields=link - with this api call, you will get a link to the user profile.
  • Ninja
    Ninja almost 7 years
    can you please give some brief about me?fields=link? Means how to use this with API?
  • andyrandy
    andyrandy almost 7 years
    you just add all the fields you want, separated with a comma, just as you wrote it. you can test it in the api explorer: developers.facebook.com/tools/explorer/… how exactly you use it depends on the sdk (if you even use any sdk).
  • Atan
    Atan almost 6 years
    Getting the profile URL using the link parameter doesn't work anymore according to this post: developers.facebook.com/blog/post/2018/04/19/… as ASIDs currently aren't resolved due to abuse.
  • andyrandy
    andyrandy almost 6 years
    thanx, i will add it to the answer!
  • alexanoid
    alexanoid over 5 years
    the link field is not marked as Returns no data as of April 4, 2018. according to the following Facebook documentation developers.facebook.com/docs/graph-api/reference/v2.2/user Why do you think it is hidden?
  • andyrandy
    andyrandy over 5 years
    who thinks that it is hidden? i specifically mentioned that field in my answer. you just do not get the "real" url, just try it.