iPhone Development: Fetch friend list from Facebook in IOS

Facebook is a most popular social platform used in today’s world. So most of application demands to use Facebook functionality in the iPhone app. I am not discussing or telling all the things that most of the iPhone apps integrates, but i am just going to show you that how you can fetch or get logged-in user’s friends from Facebook using Facebook native SDK for IOS.

For getting friends list of logged-in user, you can use requestForMyFriends method of FBRequest class.This method will give you dictionary of logged-in user friends on successful completion or execution.

Don’t worry about the code that does the same.Below is the code that shows how you can do it in IOS

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


                        NSLog(@”Found: %i friends”, friends.count);
                        for (NSDictionary* friend in friends) {
                            NSLog(@”I have a friend named %@ with id %@”, friend.name, friend.id);
                        }
                    }];

In the above code, firstly we created an object of FBRequest class and calls our class method requestForMyFriends.Then we start our process with request completionHandler, and this handler will return us a list of friends on successful completion otherwise will show error,

NOTE:- Please add Facebook SDK for IOS to your project and other framework dependencies.

Attention:- With new version of Facebook SDk, you will only see list of friends who are using the same app, the one you are using to get friend list.