查找或匹配用户联系人与 Facebook 好友的最佳方式?

发布于 2024-12-22 18:37:22 字数 2248 浏览 2 评论 0原文

我有一个用户,该用户有很多联系人(一些联系人有“姓名”,所有联系人都有“电子邮件”)。联系人有一个 image_url 字段,我想显示该联系人的图片。我想从 Facebook 上提取这些照片。

假设 User.first 的电子邮件地址为“[email protected]”,已注册与脸书。

用户有_许多联系人&&联系人属于用户。

User.first.contacts 
#<Contact id: 1, ctct_name: "Stacy Blah", ctct_email: "[email protected]", user_id: 1, img_url: nil>, 
#<Contact id: 2, ctct_name: nil, ctct_email: "[email protected]", user_id: 1, img_url: nil>, 
#<Contact id: 3, ctct_name: "John Doe", ctct_email: "[email protected]", user_id: 1, img_url: nil>

我的网站上有 fb_graph (使用 Devise :omniauthable)。

当 User.first 连接到 Facebook 时,我可以访问他们的 fb 令牌。所以我可以这样做:

facebook_user = FbGraph::User.new('me', :access_token => access_token).fetch
user_friends = facebook_user.friends

现在查找或匹配 User.first.contacts 与 user_friends 的最佳方法是什么? 理想情况下,我只需在 Facebook connect 中搜索电子邮件,如下所示:

email = Contact.first.ctct_email
search = FbGraph::User.search(email, :access_token => access_token = user['credentials']['token']) 
Contact.first.img_url = search[0].picture # or something like this

但是 Facebook API 不会公开 user_friends 电子邮件!那么,我能做什么呢?

我一直在尝试根据名称进行匹配,但遇到两个问题:(1)contacts.name 可能为零,(2)user_friends.select {|f| f.name.include?("John Doe")} 限制性太强,名称不完全匹配(例如,contact.name = "John Doe",但 Facebook 将此人称为“John X. Doe”)。

我还尝试使用名称参数 = User.first.contacts[2].name 搜索 FBGraph::User.search。

search = FbGraph::User.search("John Doe", :access_token => access_token = user['credentials']['token']) 

但随后我遇到了一个严重的歧义问题——搜索“John Doe”会出现数千个 Facebook 用户,而且他们不仅限于 user_friends!

这当然是可能的。我见过一些服务可以从 Facebook 中提取给定联系人的图像,其中的信息只有电子邮件那么少。

感谢您的帮助!!

I have a User, and that User has a bunch of contacts (some contacts have "name" and all have "email"). Contacts have a field for an image_url, and I want to show a picture for that contact. I want to pull those pictures from Facebook.

Suppose User.first has email "[email protected]", which is registered with Facebook.

User has_many contacts && Contacts belongs_to User.

User.first.contacts 
#<Contact id: 1, ctct_name: "Stacy Blah", ctct_email: "[email protected]", user_id: 1, img_url: nil>, 
#<Contact id: 2, ctct_name: nil, ctct_email: "[email protected]", user_id: 1, img_url: nil>, 
#<Contact id: 3, ctct_name: "John Doe", ctct_email: "[email protected]", user_id: 1, img_url: nil>

I have fb_graph working on my site (using Devise :omniauthable).

When User.first connects to Facebook, I have access to their fb token. So I can do this:

facebook_user = FbGraph::User.new('me', :access_token => access_token).fetch
user_friends = facebook_user.friends

Now what is the best way to find or match User.first.contacts to user_friends? Ideally, I would simply search Facebook connect for emails, like this:

email = Contact.first.ctct_email
search = FbGraph::User.search(email, :access_token => access_token = user['credentials']['token']) 
Contact.first.img_url = search[0].picture # or something like this

BUT Facebook API doesn't expose user_friends emails! So, what can I do?

I've been trying to match based on names, but I run into two problems: (1) contacts.name may be nil, and (2) user_friends.select {|f| f.name.include?("John Doe")} is too restrictive where the names don't match exactly (e.g., contact.name = "John Doe" but Facebook has this person as "John X. Doe").

I have also tried searching FBGraph::User.search with name parameter = User.first.contacts[2].name.

search = FbGraph::User.search("John Doe", :access_token => access_token = user['credentials']['token']) 

But then I have a severe disambiguation problem -- searching "John Doe" brings up thousands of Facebook users, and they aren't limited to the user_friends!

Surely this is possible. I've seen services that can pull an image from Facebook for a given contact, with as little information as an email.

Thank you for your help!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-12-29 18:37:22

您可以通过电子邮件地址搜索 Facebook 用户:

https://graph.facebook.com/[电子邮件受保护]&type=user&access_token=...

请注意,截至 2011 年 12 月 21 日,有一个 已接受错误,此功能目前无法正常工作。

You can search for the Facebook user by their email address:

https://graph.facebook.com/[email protected]&type=user&access_token=...

Note that as of 12/21/11 there is an accepted bug that this feature currently isn't working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文