Geethanjali Paleru
Geethanjali Paleru

Reputation: 39

How to fetch a list of the current users' friends who also use my app?

My requirement is to find the list of friends who installed the application.

Here I need to give the input as application id, based on this application id I need to get the users who have installed this application.

Upvotes: 0

Views: 8256

Answers (4)

user3093087
user3093087

Reputation: 36

If you are using Koala, you can do this way

In the controller user.rb

@user = User.all

In the model user.rb

def friends_using_app
facebook { |fb| fb.get_connection("me", "friends?fields=installed") }
end

In the view

 <% friends = current_user.friends_using_app %>
 <% friends_using_app = friends.find_all {|x| x['installed'] == true}    %>
 <% friends_id = friends_using_app.map {|x| x['id']}  %>
 <% show_friends = @user.find_all{|x| x[:uid] = friends_id} %>
 <% show_friends.each do |x| %>
 <%= image_tag x.avatar %>
 <% end %>

Upvotes: 0

Drazion
Drazion

Reputation: 362

I was running into the same problem, but was still a little fuzzy on using the Facebook API with FQL. The Facebook FQL page was little to no help, so I went ahead and wrote up a quick solution for those who might be struggling with this in the future.

Suffice it to say, that the long FQL solution can be condensed into a couple lines if you are using the Facebook PHP SDK, which was very nice to see. My Facebook API Solution

Upvotes: 0

Igy
Igy

Reputation: 43816

Faster than avs099's answer (single call):

Make an API call, using an access token for that app, to /me/friends?fields=installed (or /USER_ID/friends?fields=installed for an app access token)

Upvotes: 6

avs099
avs099

Reputation: 11227

that's relatively easy:

  1. Get a list of friends using https://graph.facebook.com/me/friends call (you can use Graph API Explorer for that)

  2. For each friend, get his ID and send a request to the following Graph API: https://graph.facebook.com/FRIEND_ID?access_token=APP_ID|APP_SECRET&fields=installed

note: fields=installed is required, as per documentation

if you get back something like

{ "installed": true, "id": "FRIEND_ID" }

that means that friend has that app installed. If it's just ID coming back - then he does not have app installed.

APP_ID and APP_SECRET can be found on your app's page.

Hope that helps.

Upvotes: 2

Related Questions