Get Facebook User ID from app-scoped User ID

前端 未结 5 2042
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条回答
  •  旧时难觅i
    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]
    

提交回复
热议问题