解析接收电子邮件FB SDK

时间:2014-06-22 10:39:43

标签: ios facebook facebook-graph-api parse-platform

我在解析用户的电子邮件时遇到了麻烦。虽然fb graph api,我可以从用户那里拿走几乎所有东西。但它不包含电子邮件属性。任何想法,如何得到它?如果我做NSlog,它总是返回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];
        }
    }];
}

1 个答案:

答案 0 :(得分:1)

并非每个Facebook用户都公开与公开个人资料相同的信息,email字段就是您需要接受的字段,通常不会曝光。

您获取的userData NSDictionary将仅填充此人公开的信息,因此根据用户的需要处理丢失的密钥。

要阅读的文档: