简体   繁体   中英

Get Facebook friends with Parse.com iOS

Below is my code to get facebook friends for the user logged in.

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends" parameters:@{@"fields": @"email, name, first_name, last_name, user_friends, id"}];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
     {
         if (!error)
         {
             NSArray *friendObjects = [result objectForKey:@"data"];
             NSMutableArray *friendIds = [NSMutableArray arrayWithCapacity:friendObjects.count];
             // Create a list of friends' Facebook IDs
             for (NSDictionary *friendObject in friendObjects) {
                 [friendIds addObject:[friendObject objectForKey:@"id"]];
             }

             // Construct a PFUser query that will find friends whose facebook ids
             // are contained in the current user's friend list.
             PFQuery *friendQuery = [PFUser query];
             [friendQuery whereKey:@"fbId" containedIn:friendIds];
             [friendQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                 if (error) {

                 } else {
                     self.friendUsers = objects; // self.friendUsers in array
                     [self.tableView reloadData];
                 }
             }];

         }
     }];

Im not getting any results and im not sure why i followed the steps here https://parse.com/questions/how-can-i-find-parse-users-that-are-facebook-friends-with-the-current-user

please help

The user_friends Facebook permission only returns the friends of the user that have already approved the user_friends permission to the app.

In order for a person to show up in one person's friend list, both people must have decided to share their list of friends with your app and not disabled that permission during login. Also both friends must have been asked for user_friends during the login process. 1

So unless some of your Facebook friends have already approved that permission to that same app, you'll get an empty friend's list.

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