-1

I am trying to retrieve a list of a user's Facebook friends by using the code

[FBRequestConnection startWithGraphPath:@"/me/friends"
                             parameters:nil HTTPMethod:@"GET"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id 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);
 }
 }];

But whenever I use that code it just returns Found: 0 friends. I'm putting it inside the Viewcontroller to execute after the user logs in through Facebook. I already requested user_friends permissions and I have a friend who is signed up on the app. If it makes any difference the app is also using Quickblox SDK so if there's any way to do it with that that'd be great!

Kevin
  • 41
  • 5
  • please go through this link https://developers.facebook.com/docs/ios/ and use latest Facebook sdk – IKKA Jul 09 '14 at 13:01
  • 1
    possible duplicate of [Facebook Graph Api v2.0 me/friends returns empty, or only friends who also use my app](http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-use-m) – Tobi Jul 09 '14 at 13:10
  • I already have the latest Facebook SDK installed – Kevin Jul 09 '14 at 13:23

2 Answers2

1

use this code

FBRequest *friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary *result ,NSError *error){

    NSLog(@"Friend data :%@",result);
    NSArray *friends = [result objectForKey:@"data"];

    NSLog(@"friends :%@",friends);

    for (NSDictionary<FBGraphUser>* friend in friends) {

        NSLog(@"I have a friend named %@ with id %@",friend.name,friend.id);

    }     
}];
IKKA
  • 6,297
  • 7
  • 50
  • 88
  • When I used this I got Friend data: (null) and friends: (null) – Kevin Jul 09 '14 at 13:02
  • @user3820460,any of your friend should use Facebook app you created,I think not get all of your friends list,which of friends use app,only that list is retrieved – IKKA Jul 09 '14 at 13:04
  • I had one of my friends login to the app through the simulator and he has an account, but it's obviously not installed on his phone or anything, he just logged in through the simulator. – Kevin Jul 09 '14 at 13:07
  • @user3820460,then you will get friend list array contain one member,check all permissions user_friends,etc... – IKKA Jul 09 '14 at 13:11
  • I should only need permission for user_friends right? I already have that. – Kevin Jul 09 '14 at 13:17
1

Have a look at Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

This is by design and has been discussed dozens of times here.

Community
  • 1
  • 1
Tobi
  • 31,405
  • 8
  • 58
  • 90
  • I requested user_friends permission, and I have a friend who is registered on the app, so he should be showing up according to that answer right? – Kevin Jul 09 '14 at 13:16
  • Sorry I'm new to asking questions on stackoverflow. I edited it. – Kevin Jul 09 '14 at 13:20