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

戏子无情 提交于 2019-11-27 03:36:48

问题


- (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.


回答1:


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



来源:https://stackoverflow.com/questions/23693392/facebook-api-how-to-get-the-fb-login-users-unique-id-id-from-api-doesnt-matc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!