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

坚强是说给别人听的谎言 提交于 2020-12-01 10:47:31

问题


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.


回答1:


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.




回答2:


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]



回答3:


You also get real facebook id from app scoped user id. Solution here https://stackoverflow.com/a/34450491/2181069



来源:https://stackoverflow.com/questions/24274876/get-facebook-app-scoped-user-id-from-global-facebook-id-or-username

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!