Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Facebook User ID from app-scoped User ID

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 always used the Real Time Updates and graph API calls like "https://graph.facebook.com/{postId}/comments" to analyze user activity on the Facebook page where the app was. But since these data contain the original user ID, I'm not able to match the activities to my registered users anymore!

So is there a way to get the original Facebook user ID from an app-scoped user ID? Or the other way round?

EDIT:

I ended up fetching the app-scoped IDs for all my users using the API method mentioned here: https://stackoverflow.com/a/29154912/3432305 and stored them in my database in addition to the old ID. Then, whenever an RTU arrived, for "old users" I would check which user has this app-scoped ID and process the update. At least Facebook managed to fix the bug mentioned in the comments (Get Facebook User ID from app-scoped User ID) a few days before the API v1.0 was deprecated, so for new users of my apps, it works like a charm. So far...

like image 505
kolli Avatar asked May 22 '14 11:05

kolli


People also ask

What is PSID in Facebook API?

The User Profile API allows you to use a Page-scoped ID (PSID) to retrieve user profile information that can be used to personalize the experience of people interacting with your Messenger.


1 Answers

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

like image 139
林果皞 Avatar answered Sep 28 '22 06:09

林果皞