Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API: How to get the FB login user's unique ID? ID from API doesn't match 'real' user ID in v2.0

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user 
{
    self.profilePictureView.profileID = user.objectID;
    self.nameLabel.text = user.name;
    NSLog(@"My ID:%@", user.objectID);
}

I have tried to print the user id using the above code. And what I get is 3176144783XXXXX.

However, I got a different one using this online tool http://findmyfacebookid.com/. The result is 1000042591XXXXX.

Does anyone know the difference? Why do my app and 'findmyfacebookid.com' receive a different user ID for the same user?

Note: My mobile app need to use the FB unique ID to create my own user database. So this is the reason I need a unique ID.

like image 287
Zidong Avatar asked May 16 '14 05:05

Zidong


People also ask

How do I get my Facebook API User ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

How do I find Facebook user data?

You can get user data by using the Facebook Graph API if the user has given their permission to share their data and your app has the appropriate permissions to receive this data. This topic shows you how to make a single request for data and how to have a batch of requests in a single request.


1 Answers

Since v2.0 of the Facebook API the user IDs returned to your app are scoped to your app (i.e each app receives a different identifier for any given user) - you can't compare what that site is telling you to what your app received when you called user.objectID because they're intentionally different strings

Use the ID returned to your app as the identifier for users in your app - there's no need to try and find the 'real' or 'old' user ID - there's no reason for you to need to use the user ID given to any other app ID

There's more information about that the changes from v1.0 to v2.0 here: https://developers.facebook.com/docs/apps/upgrading

And the app-scoped IDs are specifically discussed here, including a way for developers with multiple apps to corelate the IDs for users who use more than one of their apps : https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

like image 50
Igy Avatar answered Oct 03 '22 18:10

Igy