[英]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.