0

I have a problem i implement Facebook SDK in my view controller and want to get list of friends and email using Facebook. I wrote this:

FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions:@[@"public_profile", @"email", @"user_friends"]];

loginView.delegate = self;

and then use the protocol method of FBLoginViewDelegate:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user 
{
  self.profilePictureView.profileID = user.id;
  self.nameLabel.text = user.name;
  NSLog(@"%@", user);
  NSLog(@"%@", [user objectForKey:@"email"]);
}

In console i got this:

2014-12-04 14:56:48.746 FBLoginUIControlSample[2941:613] 

"first_name" = Pavel;
gender = male;
id = 1379600000000000;
"last_name" = name;
link = "https://www.facebook.com/app_scoped_user_id/1379600000000000/";
locale = "ru_RU";
name = "Pavel name";
timezone = 2;
"updated_time" = "2014-12-03T11:47:13+0000";
verified = 1;

2014-12-04 14:56:48.748 FBLoginUIControlSample[2941:613] (null)
Rumin
  • 3,787
  • 3
  • 27
  • 30

3 Answers3

2

sorry , but you can't

Read Facebook Permissions

you only can get the email when the user login , but you can't get user's friends email.

i am not really sure but maybe you can use "friendsusername"@facebook.com ("facebook email").

i found this, https://www.facebook.com/help/224049364288051

the person has to active @facebook option.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
ingrid
  • 47
  • 3
0

For friends with Facebook SDK 3.0 you can do this

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.id);
    }
}];

You can not access to any users email, excepts of yours.
Because FBGraphUser doesn't have an email @property, we can't access the information like with the name (dot-syntax), however the NSDictionary still has the email kv-pair and we can access it like we would do with a normal NSDictionary. With this method you can access to your email.

if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
         if (!error) {
             self.nameLabel.text = user.name;
             self.emailLabel.text = [user objectForKey:@"email"];
         }
     }];
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
gronzzz
  • 617
  • 6
  • 15
  • 1
    That's not gonna work. Friends permissions have been dismissed with the v2.0 Graph API, and getting the email addresses of friends was **never** possible, even with v1.0 – Tobi Dec 04 '14 at 13:56
  • Of friends no, but he need to get user email – gronzzz Dec 04 '14 at 14:33
-2

hope this will help you

you can get your friend list by using below code in your viewDidLoad

[FBRequestConnection startWithGraphPath:@"me/taggable_friends"
                                 parameters:nil
                                 HTTPMethod:@"GET"
                          completionHandler:^(
                                              FBRequestConnection *connection,
                                              id result,
                                              NSError *error
                                              ) {

                          }];

and some info

EDIT

the above answer only mention for friendlist not email(as its already quite clear by above answers) , now what you want friendlist

A friend list(Friend List V 2.2) - an object which refers to a grouping of friends created by someone or generated automatically for someone (such as the "Close Friends" or "Acquaintances" lists)

from v2.0 you'll only be able to get all friends via the /me/taggable_friends (see it by result)

Community
  • 1
  • 1
Anurag Bhakuni
  • 2,379
  • 26
  • 32