简体   繁体   English

我有一个Facebook用户登录了我的应用程序。 如何获得他朋友的身份证?

[英]i have a facebook user logged in my app. how to get ID's of his friends?

If I have in my web application a facebook user logged in. I want then to be able to post to his friends sth on their new's feed. 如果我的Web应用程序中有一个facebook用户登录。那么我希望能够将其新消息的源发布给他的朋友。 For this I need an ID of his friend that i want to post to.(at least I think I should need an id or maybe there is some other way). 为此,我需要我要发布给他朋友的ID(至少我认为我应该需要一个ID,否则可能还有其他方法)。

So the question is how to get the ID's of his friends. 因此,问题是如何获取他朋友的ID。 I can get all the names of his friends with facebook_user.friends. 我可以通过facebook_user.friends获得他所有朋友的名字。 Or i can also get the first one with facebook_user.friends.first. 或者,我也可以通过facebook_user.friends.first获得第一个。

So the question is how to get the ID of a specific friend depending on his/her name? 因此,问题是如何根据特定朋友的姓名获取其ID?

I was searching google and reading through the facebook documentation but couldn't find anything so I would appreciate any answer. 我正在搜索google并阅读了Facebook文档,但找不到任何内容,因此我希望得到任何答复。 Thank you. 谢谢。

(I am using facebooker2 and mogli gem to interact with posting to walls etc.) (我正在使用facebooker2和mogli gem与张贴到墙壁等进行交互。)

Try using the fbgraph gem for RoR. 尝试将fbgraph gem用于RoR。 You can do something like this in your controller. 您可以在控制器中执行类似的操作。

user = FbGraph::User.me(ACCESS_TOKEN)

 friendslist = user.friends

friendslist will be an array of details of the user's friends and can be filtered easily. 好友列表将包含用户好友的详细信息数组,并且可以轻松进行过滤。

Calling http://graph.facebook.com/youruser/friends will return all of the user's friends data. 调用http://graph.facebook.com/youruser/friends将返回用户的所有朋友数据。 Of course you will need the correct extended permissions as well as a valid auth token. 当然,您将需要正确的扩展权限以及有效的身份验证令牌。

If you want to access the friends with graph.facebook.com/youruser/friends then you have use a gem like RestClient. 如果您想通过graph.facebook.com/youruser/friends访问朋友,则可以使用RestClient之类的gem。

for eg the facebook access token can be obtained by 例如,可以通过以下方式获取facebook访问令牌

access_code = RestClient.get 'https://graph.facebook.com/oauth/access_token',
                     {:params => {:client_id => ENV['app_id'].to_s,
                      :redirect_uri => ENV['redirect_uri'],
                      :client_secret => ENV['app_secret'].to_s,
                      :code => code.to_s}}

Similarly you can obtain your friends too. 同样,您也可以找到您的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的网站上更新用户的Facebook朋友? - How to update a user's friends from facebook on my site? 如何通过koala在facebook中获取任何用户的朋友列表 - how to get any user's friends list in facebook by koala 如何在Rails中使用OmniAuth来结识我的Facebook朋友? - How to get my Facebook friends with OmniAuth in Rails? 使用Facebook Graph API查找用户的朋友 - Finding user's friends with Facebook Graph API 将用户的Facebook好友列表存储在我的数据库中的最佳方法是什么? - What is the best way to store a user's Facebook friends list in my database? 如何将我的Facebook应用程序用户与我的Web应用程序用户相关联? - How do I associate my facebook app user with my web app user? 无法安装我的Rails应用程序的引擎设计。 我有5条关于此的错误消息 - unable to install the engine devise for my rails app. I have 5 error messages pertaining to it SonarQube插件,如何获取页面上当前登录的用户ID? - Plugin for SonarQube, how to get currently-logged-in user id on a page? 我在Rails应用程序中有一个名为Image的资源。 如何访问动态生成的路径助手? - I have a resource named Image in a Rails app. How can I access the dynamically generated path helpers? 如果用户通过 Facebook 登录并且没有提供他的电子邮件,我如何显示错误 - How can I show an error if user signs in via Facebook and desn't provide his email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM