0

I am integrating facebook login.I need to display friends name and location. name is displaying but location is showing null. The below is my code. Tell me where i am going wrong.

if (FBSession.activeSession.isOpen)
   {
        NSLog(@"active fb session");
        FBRequest* friendsRequest = [FBRequest requestForMyFriends];

        [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                      NSDictionary* 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.location);
        }
        }];
    }
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90

1 Answers1

0

Add the permission: friends_location in your login code.

Note that:

  1. API for getting the friends location: /me/friends?fields=location,name; and you're calling for default: /me/friends

  2. You'll get the location as an object:

    "location": {
       "id": "130646063637019", 
       "name": "Noida, India"
    }, 
    

    And you'll not get location for all the friends of-course (due to their privacy settings).

Live Demo

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • @Sahil Mittal can you help me? What is the reason for that: from one user I get field "location" in result from Facebook (my example is location = { id = 107677462599905; name = "Minsk, Belarus"; }; but from other users I don't receive this field, but both of them have current location in Facebook profile. – Alexander Yakovlev May 26 '14 at 08:00
  • De-authorize that user by removing the app from the settings and then try again! – Sahil Mittal May 28 '14 at 09:02