9

I am trying to get a list of all my Facebook Friends, who are using the App I am getting the list of all friends, but how do I filter all the friends which are using the app?

    FBRequest* friendsRequest = [FBRequest requestForMyFriends];
    [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                  NSDictionary* result,
                                                  NSError *error) {
        NSArray* friends = [result objectForKey:@"data"];
        NSLog(@"Found: %i friends", friends.count);
        for (NSDictionary<FBGraphUser>* friend in friends) {
            NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);

        }
        NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
            return friend.id;
        }];

    }];

Thanks.

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Fry
  • 922
  • 2
  • 10
  • 24

5 Answers5

7

Thats the way how it works with iOS5+

FBRequest* friendsRequest = [FBRequest requestWithGraphPath:@"me/friends?fields=installed" parameters:nil HTTPMethod:@"GET"];
        [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                      NSDictionary* result,
                                                      NSError *error) {
            NSArray* friends = [result objectForKey:@"data"];
            NSLog(@"Found: %i friends", friends.count);
            for (NSDictionary<FBGraphUser>* friend in friends) {
                NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);

            }
            NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
                return friend.id;
            }];

     }];
Fry
  • 922
  • 2
  • 10
  • 24
7

This can be used for latest Facebook API 3.2 ,

[FBRequestConnection startForMyFriendsWithCompletionHandler:
     ^(FBRequestConnection *connection, id<FBGraphUser> friends, NSError *error)
     {
         if(!error){
             NSLog(@"results = %@", friends);
         }
     }
];
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Bhushan
  • 175
  • 1
  • 9
2

"is_app_user" that you need to check.

- (void)getFriends
{

    NSString *query = @"select uid, name, is_app_user "
    @"from user " 
    @"where uid in (select uid2 from friend where uid1=me() )";
    NSDictionary *queryParam =
    [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
    // Make the API request that uses FQL
    [FBRequestConnection startWithGraphPath:@"/fql"
                                 parameters:queryParam
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                              NSError *error) {
                              if (error) {
                                  DLog(@"Error: %@", [error localizedDescription]);
                                  [self.delegate FBDidFailedLoadFriends:error];
                              } else { 
                                  DLog(@"Result: %@", result);
                              }
                              DLog(@"%@",((FBGraphObject*)result)[@"data"]);
                          }];
}
Narek Safaryan
  • 140
  • 1
  • 7
1

You can do it with FQL. It will directly give list of friends who are using app.

SELECT uid FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ?)
AND is_app_user = 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
0

Should be closed as Facebook has changed the way you can access the friends list. Now all you can access is app users.

laving
  • 49
  • 6