简体   繁体   中英

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.

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

     }];

This can be used for latest Facebook API 3.2 ,

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM