Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Facebook app-scoped user id from global Facebook id, or username

If you have a Facebook, for instance Zuckerbergs user id '4', or username, 'zuck', how do you get the new app-scoped id with Graph v2.0 using the app's access token? Can't seem to find anything about this in the docs.

like image 592
seaders Avatar asked Jun 17 '14 23:06

seaders


People also ask

How do I find the scoped user ID on Facebook?

(To get a scoped User ID for a Page, your app must query the endpoint using that Page's access token.) Your appsecret_proof hash. Refer to our Facebook Login Security guide for more information.

What is a Facebook app user ID?

User ID. Your User ID is a string of numbers that doesn't personally identify you but does connect to your Facebook profile. You have a User ID automatically, whether or not you choose to create a username. Learn how to find your user ID.

What is app scoped ID?

Those of you who use the Facebook Graph API know that there were some big changes with the release of version 2.0. One of the biggest? Instead of returning a user's Facebook ID, the API is now returning an app_scoped_user_id, a unique identifier to each app/user combo.


2 Answers

This is basically the answer given to the other-way-around question, Get Facebook User ID from app-scoped User ID .

Basically, easiest straight forward flow is a call to https://graph.facebook.com/?ids=http://facebook.com/[FBID/USERNAME]&access_token=[APP_ID]|[APP_SECRET]

Doing that for Zuckerberg, will give you the familiar

{
  "http://facebook.com/4":
  {
    "id": "4",
    "first_name": "Mark",
    "gender": "male",
    "last_name": "Zuckerberg",
    "link": "https://www.facebook.com/zuck",
    "locale": "en_US",
    "name": "Mark Zuckerberg",
    "username": "zuck"
  }
}

But, if that user had only logged in to your app for the first time after 30th May 2014 (the changeover date), he'd have something like...

{
  "http://facebook.com/4":
  {
    "id": "277123456789101",
    "first_name": "Mark",
    "gender": "male",
    "last_name": "Zuckerberg",
    "link": "https://www.facebook.com/zuck",
    "locale": "en_US",
    "name": "Mark Zuckerberg",
    "username": "zuck"
  }
}

Giving you the 277... app-scoped id for your app.

like image 73
seaders Avatar answered Oct 08 '22 05:10

seaders


In addition to the comment by @Raymond Yee, you have to provide APP_ID, APP_SECRET and FACEBOOK_USER_ID (note that this is the numeric id, not the username):

So it works with this URL:

https://graph.facebook.com/v2.3?access_token=[APP_ID]%7C[APP_SECRET]&ids=[FACEBOOK_USER_ID]
like image 32
Deyan Vitanov Avatar answered Oct 08 '22 06:10

Deyan Vitanov