0

I am in trouble with parse user`s email. I can take from user almost everything though fb graph api. But it does not contain email property. Any idea, how to get it? If I do NSlog it always returns null.

{
    NSArray *permissionsArray = @[@"email", @"basic_info"];
    [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
        // Was login successful ?
        if (!user) {
            if (!error) {
                NSLog(@"The user cancelled the Facebook login.");
            }else {
                NSLog(@"An error occurred: %@", error.localizedDescription);
            }
            // Callback - login failed
            if ([delegate respondsToSelector:@selector(commsDidLogin:)]) {
                [delegate commsDidLogin:NO];
            }
        }else if (user.isNew) {
            NSLog(@"User signed up and logged in through Facebook!");
            [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error) {
                    NSDictionary<FBGraphUser> *prop = (NSDictionary<FBGraphUser> *)result;
                    NSDictionary *userData = (NSDictionary *)result;
                    [[PFUser currentUser] setObject:prop.id forKey:@"fbid"];
                    [[PFUser currentUser] saveInBackground];
                    [[PFUser currentUser] setObject:prop.first_name forKey:@"firstname"];
                    [[PFUser currentUser] saveInBackground];
                    [[PFUser currentUser] setObject:prop.last_name forKey:@"lastname"];
                    [[PFUser currentUser] saveInBackground];
                    NSString *mail = userData[@"email"];
                    [[PFUser currentUser] setObject:mail
                                             forKey:@"email"];
                    [[PFUser currentUser] saveInBackground];


                    NSLog(@"prop %@", prop);



                }else {
                    NSLog(@"User logged in through Facebook!");
                    NSLog(@"Welcome Screen I am %@", [[PFUser currentUser] username]);
                }
            }];
        }
        else {
            //HERE
            NSLog(@"Error getting the FB username %@", [error description]);
        }
        [[PFUser currentUser] saveInBackground];
        // Callback - login successful
        if ([delegate respondsToSelector:@selector(commsDidLogin:)]) {
            [delegate commsDidLogin:YES];
        }
    }];
}
zx81
  • 41,100
  • 9
  • 89
  • 105
Milan1111
  • 185
  • 3
  • 13

1 Answers1

1

Not every Facebook user exposes the same information as part of their public profile, the email field is one in particular where you need to accept that this will often NOT be exposed.

The userData NSDictionary you get back will only be populated with information the person has made public, so handle missing keys as needed per user.

Documentation to read:

Timothy Walters
  • 16,866
  • 2
  • 41
  • 49
  • But if the user agree with the permissions, I can get his email, can`t I? There must be a way how to get the email, don`t you know about any? – Milan1111 Jun 22 '14 at 22:03
  • @Milan1111 refer to the documentation links, if you've setup your permissions correctly and issue your graph query correctly you will get the information if it exists – Timothy Walters Jun 22 '14 at 22:14