Reputation: 7173
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. 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).
So the question is how to get the ID's of his friends. I can get all the names of his friends with facebook_user.friends. Or i can also get the first one with facebook_user.friends.first.
So the question is how to get the ID of a specific friend depending on his/her name?
I was searching google and reading through the facebook documentation but couldn't find anything so I would appreciate any answer. Thank you.
(I am using facebooker2 and mogli gem to interact with posting to walls etc.)
Upvotes: 0
Views: 631
Reputation: 1016
If you want to access the friends with graph.facebook.com/youruser/friends then you have use a gem like RestClient.
for eg the facebook access token can be obtained by
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.
Upvotes: 0
Reputation: 1016
Try using the fbgraph gem for 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.
Upvotes: 1
Reputation: 66465
Calling http://graph.facebook.com/youruser/friends will return all of the user's friends data. Of course you will need the correct extended permissions as well as a valid auth token.
Upvotes: 0