Get Facebook User ID from app-scoped User ID

前端 未结 5 2034
Happy的楠姐
Happy的楠姐 2020-11-28 05:34

With the upgrade from Facebook Graph API v1.0 to v2.0, Facebook is using \"App-scoped User IDs\", so I cannot see the \"original\" user ID inside my apps anymore.

I

相关标签:
5条回答
  • 2020-11-28 05:54

    there's no (simple/obvious) possibility to get a real user id based on an app-scoped user id.

    0 讨论(0)
  • 2020-11-28 05:54

    From your conversation between Johannes N.

    Can I get the app-scoped ids (for apps I own) via the original user id. that would help too.

    To get app-scoped ids from original user id can be easily done via:

    https://graph.facebook.com/v2.0/?ids=http://www.facebook.com/USER_ID&access_token=ACCESS_TOKEN

    enter image description here

    Yo can use fields parameter to return only id:

    https://graph.facebook.com/v2.0/?ids=http://www.facebook.com/USER_ID&fields=id&access_token=ACCESS_TOKEN

    enter image description here

    The benefit of ids instead of id because you can query multiple ids:

    enter image description here *www can be remove to minimize characters count.

    To get app-scoped ids from username can be easily done too:

    https://graph.facebook.com/v2.0/?ids=http://www.facebook.com/USERNAME&access_token=ACCESS_TOKEN

    enter image description here

    0 讨论(0)
  • 2020-11-28 06:09

    I found a website can help you get facebook user id from app scoped id.

    It's here http://izitools.com/en/tool/get-facebook-id-from-scoped-id

    API

    0 讨论(0)
  • 2020-11-28 06:12

    there is a dirty hack to retrieve original user id

    http://graph.facebook.com/app-scoped-id this returns the facebook public information as follows, { "id": "app-scoped-id", "first_name": "xxxx", "gender": "male", "last_name": "yyyy", "link": "https://www.facebook.com/zzzz", "locale": "en_US", "name": "xxxx yyyy", "username": "zzzz" }

    Then you make another graph api call with username http://graph.facebook.com/zzzz

    This will returns the original facebook id and other public information, instead of app-scoped-id

    0 讨论(0)
  • 2020-11-28 06:13

    You can't go from scoped back to real. Your best bet is converting all of them to scoped. It's pretty easy:

    https://graph.facebook.com/?ids=REAL_ID&access_token=APP_ID|APP_SECRET

    Here's some simple Ruby code that does this:

    require 'open-uri'
    require 'json'
    
    json = JSON.load(open("https://graph.facebook.com/?ids=#{real_id}&access_token=#{FACEBOOK_APP_ID}|#{FACEBOOK_APP_SECRET}"))
    scoped_id = /app_scoped_user_id\/(\d+)\//.match(json[real_id.to_s]['link'])[1]
    
    0 讨论(0)
提交回复
热议问题