Facebook API: How to Get the Fb Login User's Unique Id? Id from API Doesn't Match 'Real' User Id in V2.0

Facebook UID from response doesn't match with user's uid stored in database

With API v2.0, Facebook introduced app-scoped user ids.

For every new user that logs in to your app after the switch was made to 2.0, you will not get their “global” user id any more, but only an app-scoped one, that is unique to your app - to be more specific, it is tied to your app id.

So if you are using different app ids, resp. switched app ids at some point, of course you will get different app-scoped ids for the same user.

If you have a business that has several apps, you can connect them via Business Manager, so that you can connect the different app-scoped user ids for different apps.

Get Facebook User ID from app-scoped User ID

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

Facebook API - different user ID's for each app?

Well, this is very old news. It's been like that since April 30th 2014. With the introduction of the graph API v2.0, FB also introduced the Business Mapping API, which is designed for your use case.

You won't receive one user id, but you'll receive a token_for_business:

This returns a string which is the same for this person across all the apps managed by the same Business Manager.

See

  • https://developers.facebook.com/docs/apps/for-business#field
  • https://developers.facebook.com/docs/apps/for-business#api
  • https://developers.facebook.com/docs/apps/business-manager#create-business

How to Convert Facebook fake user id to real user id

Since April 2014 (v2.0 of the Graph API), it´s not possible to get the "real" ID anymore, you only get an "App Scoped ID". It´s not a fake one, it´s unique in that specific App so you can still use it to identify returning users.

It´s not possible to get the "username" either anymore, as it would allow someone to get the real ID.

Check out the changelog for more information: https://developers.facebook.com/docs/apps/changelog

How to get the Facebook user id using the access token

If you want to use Graph API to get current user ID then just send a request to:

https://graph.facebook.com/me?access_token=...

Facebook JS SDK's FB.api('/me') method doesn't return the fields I expect in Graph API v2.4+

You need to manually specify each field since Graph API v2.4:

  • https://developers.facebook.com/docs/apps/changelog#v2_4
  • https://developers.facebook.com/docs/javascript/reference/FB.api

Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

E.g.

FB.api('/me', 'get', { access_token: token, fields: 'id,name,gender' }, function(response) {
console.log(response);
});

Facebook user url by id

UPDATE 2: This information is no more given by facebook. There is an official announcement for the behavior change (https://developers.facebook.com/blog/post/2018/04/19/facebook-login-changes-address-abuse/) but none for its alternative.

Yes, Just use this link and append your ID to the id parameter:

https://facebook.com/profile.php?id=<UID>

So for example:

https://facebook.com/profile.php?id=4

Will redirect you automatically to https://www.facebook.com/zuck Which is Mark Zuckerberg's profile.

If you want to do this for all your ids, then you can do it using a loop.

If you'd like, I can provide you with a snippet.

UPDATE: Alternatively, You can also do this:

https://facebook.com/<UID>

So that would be: https://facebook.com/4 which would automatically redirect to Zuck!



Related Topics



Leave a reply



Submit