4

This has been asked plenty of times on Stack Overflow, but all answers explain how to convert a Facebook profile ID to an app_scoped_user_id. I am asking for exactly the opposite:

  • I have an app_scoped_user_id, provided by Facebook Graph API.
  • I want the global profile ID, so I can output the link to the user's Facebook page.

Here is the flow of my PHP application:

When authenticating with my own Facebook account, this is the contents of the Graph Object:

array (size=11)
  'id' => string '1117686364915316' (length=16)
  'email' => string 'greg.bowler@g105b.com' (length=21)
  'first_name' => string 'Greg' (length=4)
  'gender' => string 'male' (length=4)
  'last_name' => string 'Bowler' (length=6)
  'link' => string 'https://www.facebook.com/app_scoped_user_id/1117686364915316/' (length=61)
  'locale' => string 'en_GB' (length=5)
  'name' => string 'Greg Bowler' (length=11)
  'timezone' => int 1
  'updated_time' => string '2015-06-23T10:12:53+0000' (length=24)
  'verified' => boolean true

From this, I need to be able to provide a link to my Facebook account. This can easily be done by knowing the Facebook account's ID, buy going to http://facebook.com/profile.php?id=XXXXX, which will even redirect to the correct page if you have named your account.

However, the ID that is specified in the Graph Object response is not my global Facebook ID; it is a app_scoped_user_id, specific to the application I'm authenticating with.

How can I convert the app_scoped_user_id to the global ID of my account?

For example, the website http://findmyfacebookpageid.com/ does this, although its source code is closed.

I can provide my app_scoped_user_id to the service here: http://findmyfacebookpageid.com/get.php?url=https://www.facebook.com/app_scoped_user_id/1117686364915316

and it returns:

{
facebook_id: "100000218905189"
}

To prove this question is answerable, I can use the returned facebook_id value to access my actual Facebook page by visiting http://facebook.com/profile.php?id=100000218905189

Greg
  • 21,235
  • 17
  • 84
  • 107
  • _“I want the global profile ID, so I can output the link to the user's Facebook page”_ – you don’t need a global id for that. You’ve got a `link` property already in the API output you have shown, and that is all you need to link to a user profile. When someone visitis that URL in their browser, Facebook will automatically redirect them to the “correct” address. – CBroe Jun 25 '15 at 14:25
  • @CBroe the problem is that following an app-scoped user link requires that the user is logged in to see the profile. Imagine building a social network hub like about.me, where you want to list the public accounts for the world to see. – Greg Jun 25 '15 at 14:27
  • If I am not logged in, http://facebook.com/profile.php?id=100000218905189 doesn’t show me anything besides your profile picture and name either … I think you can assume that if someone follows an external link to your FB profile, they should be willing to login to Facebook as well, if they want to see more details about your profile. – CBroe Jun 25 '15 at 14:30
  • @CBroe it still seems like it would be easier if Facebook just provided the ID in the response, but I agree with you about being logged in... just seems like I'm being made to run in circles by FB for a simple task like this. Thanks for your input. – Greg Jun 25 '15 at 14:32
  • If they still provided the global user id, then introducing app-scoped user ids would have been pointless in the first place. – CBroe Jun 25 '15 at 14:33
  • possible duplicate of [Get Facebook User ID from app-scoped User ID](http://stackoverflow.com/questions/23805866/get-facebook-user-id-from-app-scoped-user-id) – Greg Jun 25 '15 at 19:27

1 Answers1

3

This question has been asked a few times (Get Facebook User ID with Facebook App Scope ID)

You should not be able to get the global ID from the app-scoped ID. Facebook is slowly fixing every method there is to find it, as they are considered "hacks".

Since you mentioned it, from a user's profile page there are ways to find your global ID which will probably fixed by Facebook in time too, but if you are still interested, some of the answers to this (How to find my own facebook ID? (not the app-scoped ID)) question might be useful.

Community
  • 1
  • 1
  • Maybe I'm asking the wrong question? All I want is to be able to output the URL of the user's profile to the screen, so I can output a link to go to their profile. – Greg Jun 25 '15 at 13:34
  • If you want to link to their profile and you have the app-scoped ID, you can just link to https://www.facebook.com/app_scoped_user_id/{app-scoped-id}/ and it should redirect to the user's profile. – Juan Carlos Carbonell Jun 25 '15 at 13:52
  • 1
    unfortunately this is not the case. I am presented with a Facebook login page, even though my profile is public. Also, I want the ID so I can display my profile picture like this http://graph.facebook.com/100000218905189/picture - without the global ID this would be impossible would it not? – Greg Jun 25 '15 at 13:55
  • 1
    I believe you are right, you need to be logged in facebook for the http://www.facebook.com/app_scoped_user_id{app-scoped-id}/ link to work. The profile picture though, I believe you can display it using an app-scoped ID: http://graph.facebook.com/1117686364915316/picture?type=normal (I just tested it with your ID and it worked) – Juan Carlos Carbonell Jun 25 '15 at 14:09