How can I count the number of Facebook friends in iOS sdk?

I am trying to figure out how to get a random user ID from my friends.

Is there a way to do this using the "friendPickerController"? the only β€œcounting” method that I have found is in a selection that does not help.

+4
source share
2 answers

You can get the total number of friends using the following method

FBRequest* friendsRequest = [FBRequest requestForMyFriends]; [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary* result, NSError *error) { NSArray* friends = [result objectForKey:@"data"]; NSLOG(@"Total Friend :%@",friends.count); }]; 
+5
source

Just an update in case this helps anyone. While Dipak's answer worked flawlessly for me at the end, it did not work until I added permission to receive the invoice. I added the following lines of code immediately before the Dipak code, and it returned me the correct count of friends.

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

Source: https://habr.com/ru/post/1434188/


All Articles