Facebook API:如何获取FB登录用户的唯一ID? API中的ID与v2.0中的“真实”用户标识不符 [英] Facebook API: How to get the FB login user's unique ID? ID from API doesn't match 'real' user ID in v2.0

查看:944
本文介绍了Facebook API:如何获取FB登录用户的唯一ID? API中的ID与v2.0中的“真实”用户标识不符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ;
self.nameLabel.text = user.name;
NSLog(@我的ID:%@,user.objectID);
}

我已尝试使用上述代码打印用户ID。而我得到的是 3176144783XXXXX



然而,我使用这个在线工具得到了一个不同的 http://findmyfacebookid.com/ 。结果是 1000042591XXXXX



有谁知道有什么区别吗?为什么我的应用程序和findmyfacebookid.com为同一用户收到不同的用户ID?



注意:我的手机应用程序需要使用FB唯一ID来创建我的拥有用户数据库。所以这就是我需要一个唯一ID的原因。

解决方案

自从Facebook API v2.0以来,用户ID返回给你应用程序的范围适用于您的应用程序(即每个应用程序为任何给定的用户收到不同的标识符) - 您无法比较该网站在您调用 user.objectID 因为它们是有意不同的字符串



使用返回到您的应用程序的ID作为应用程序中用户的标识符 - 无需尝试查找真实或旧用户ID - 没有理由需要使用给予任何其他应用ID的用户ID



有更多的信息在这里从v1.0更改为v2.0: https://developers.facebook.com/docs/apps/upgrading



这里特别讨论了应用范围的ID,包括为多个应用开发人员提供的方法为使用多个应用的​​用户提供ID: https://developers.facebook.com/docs/ apps / upgrade#upgrade_v2_0_user_ids


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

解决方案

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

这篇关于Facebook API:如何获取FB登录用户的唯一ID? API中的ID与v2.0中的“真实”用户标识不符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆