Andrey Chernukha
Andrey Chernukha

Reputation: 21808

How to know which Facebook friends of the user have my application installed?

Is it possible to implement the following? I want to create an iOS application which allows the user to see all their Facebook friends who already have this application in their Facebook list. Is it achievable via Facebook Connect or Graph API or maybe something else?

Upvotes: 1

Views: 1747

Answers (4)

wheeliebin
wheeliebin

Reputation: 735

Use Facebook login and then ask for the user's friends. You will only get those that have the requesting app installed (it used to return all friends with an 'installed' flag)

Upvotes: 0

BootMaker
BootMaker

Reputation: 1647

Yes you can do it with the new Facebook SDK 3.5 and greater (2013 June) using GraphAPI. You can use the deviceFilteredFriends mutable array later as you like...

// The Array for the filtered friends
NSMutableArray *installedFilteredFriends = [[NSMutableArray alloc] init];

// Request the list of friends of the logged in user (me)
[[FBRequest requestForGraphPath:@"me/friends?fields=installed"]
 startWithCompletionHandler:
 ^(FBRequestConnection *connection,
   NSDictionary *result,
   NSError *error) {

     // If we get a result with no errors...
     if (!error && result)
     {
         // here is the result in a dictionary under a key "data"
         NSArray *allFriendsResultData = [result objectForKey:@"data"];

         if ([allFriendsResultData count] > 0)
         {
            // Loop through the friends
            for (NSDictionary *friendObject in allFriendsResultData) {
               // Check if installed data available
               if ([friendObject objectForKey:@"installed"]) {

                  [installedFilteredFriends addObject: [friendObject objectForKey:@"id"]];
                     break;
                }
             }
          }
      }
 }];

Upvotes: 0

Daniel Huang
Daniel Huang

Reputation: 113

If you have followed the Facebook tutorial iOS Tutorial.

You should have access to a "facebook" object in your AppDelegate.m file. That "facebook" object will already have been registered with your specific application id. You can then use it to query for the current user's friends who have already installed the application.

Here is the Facebook query to retrieve friend data:

NSString *fql = [NSString stringWithFormat:@"Select name, uid, pic_small from user where is_app_user = 1 and uid in (select uid2 from friend where uid1 = %@) order by concat(first_name,last_name) asc", _replace_this_with_the_fb_id_of_the_current_user_ ];

Upvotes: 4

lmirosevic
lmirosevic

Reputation: 16307

Yes, it's possible.

  1. You will need to maintain your own database of who has installed the application.
  2. When a user installs the application, they connect to Facebook through one of the APIs, get their userID, and submit it to your database with the flag that the user installed the application.
  3. You then ask Facebook through one of its APIs for that user's list of friends' IDs, and then ask your database if any of those IDs have the associated flag set.

Upvotes: 4

Related Questions