Fry
Fry

Reputation: 922

iOS Facebook SDK - get list of Friends connected with App

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.

Upvotes: 9

Views: 13988

Answers (5)

laving
laving

Reputation: 59

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

Upvotes: 0

Bhushan
Bhushan

Reputation: 175

This can be used for latest Facebook API 3.2 ,

[FBRequestConnection startForMyFriendsWithCompletionHandler:
     ^(FBRequestConnection *connection, id<FBGraphUser> friends, NSError *error)
     {
         if(!error){
             NSLog(@"results = %@", friends);
         }
     }
];

Upvotes: 7

Narek Safaryan
Narek Safaryan

Reputation: 140

"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"]);
                          }];
}

Upvotes: 2

Fry
Fry

Reputation: 922

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;
            }];

     }];

Upvotes: 7

Somnath Muluk
Somnath Muluk

Reputation: 57846

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

Upvotes: 1

Related Questions