4

I'm trying to figure out how to get a random userID from my friends.

is there a way to do it with "friendPickerController" ? the only "count" method I've found is in the selection, which dosen't help.

Hans Then
  • 10,935
  • 3
  • 32
  • 51
Tomer Rubin
  • 173
  • 2
  • 17

2 Answers2

5

You can get the total friend count using following method

FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                  NSDictionary* result,
                                  NSError *error) {
    NSArray* friends = [result objectForKey:@"data"];


    NSLOG(@"Total Friend :%@",friends.count);
}];
Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75
Dipak Narigara
  • 1,796
  • 16
  • 18
0

Just updating in case this helps anyone. While Dipak's answer worked flawlessly for me at the end, it didn't work until I added permission to retrieve the count. I added the following lines of code just before Dipak's code and it returned me the proper friend count.

NSArray *permissions = [NSArray arrayWithObjects:@"friends_about_me", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {


                                  }];

[FBSession setActiveSession:[FBSession activeSession]];
Souvik Ghosh
  • 731
  • 8
  • 22