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:
- A Facebook Request is made to
/me
, returning a Facebook Response - On the Response, I call getGraphObject() to return a Facebook Graph Object.
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