ios Facebook API:如何获取FB登录用户的唯一ID?API 中的 ID 与 v2.0 中的“真实”用户 ID 不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23693392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook API: How to get the FB login user's unique ID? ID from API doesn't match 'real' user ID in v2.0
提问by Zidong
- (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
.
我尝试使用上面的代码打印用户 ID。而我得到的是3176144783XXXXX
。
However, I got a different one using this online tool http://findmyfacebookid.com/. The result is 1000042591XXXXX
.
但是,我使用这个在线工具http://findmyfacebookid.com/得到了一个不同的。结果是1000042591XXXXX
。
Does anyone know the difference? Why do my app and 'findmyfacebookid.com' receive a different user ID for the same user?
有谁知道区别?为什么我的应用程序和“findmyfacebookid.com”会收到同一用户的不同用户 ID?
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.
注意:我的移动应用程序需要使用 FB 唯一 ID 来创建我自己的用户数据库。所以这就是我需要一个唯一 ID 的原因。
回答by Igy
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
从 Facebook API 的 v2.0 开始,返回到您的应用程序的用户 ID 的范围仅限于您的应用程序(即每个应用程序接收任何给定用户的不同标识符)-您无法将该站点告诉您的内容与您的应用程序收到的内容进行比较当你打电话user.objectID
是因为他们故意使用不同的字符串
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
使用返回到您的应用程序的 ID 作为您应用程序中用户的标识符 - 无需尝试查找“真实”或“旧”用户 ID - 您没有理由需要使用提供给任何其他用户的用户 ID应用程序 ID
There's more information about that the changes from v1.0 to v2.0 here: https://developers.facebook.com/docs/apps/upgrading
这里有更多关于从 v1.0 到 v2.0 的变化的信息: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
此处专门讨论了应用范围的 ID,包括一种让拥有多个应用的开发人员为使用多个应用的用户关联 ID 的方法:https: //developers.facebook.com/docs/apps/upgrading# upgrade_v2_0_user_ids