解析接收电子邮件FB SDK [英] Parse receive E-mail FB SDK

查看:133
本文介绍了解析接收电子邮件FB SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决用户电子邮件时遇到麻烦。我可以从用户几乎所有东西,尽管fb图api。但它不包含电子邮件属性。任何想法,怎么得到它?如果我做NSlog,它总是返回null。

  {
NSArray * permissionsArray = @ [@email,@ 基本信息];
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser * user,NSError * error){
//登录成功?
if(!user){
if(!error){
NSLog(@用户取消了Facebook登录。
} else {
NSLog(@发生错误:%@,error.localizedDescription);
}
//回调 - 登录失败
if([delegate responsesToSelector:@selector(commsDidLogin :)]){
[delegate commsDidLogin:NO];
}
} else if(user.isNew){
NSLog(@用户注册并通过Facebook登录!);
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection * connection,id result,NSError * error){
if(!error){
NSDictionary< FBGraphUser> * prop =(NSDictionary< FBGraphUser> *)结果;
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(@用户通过Facebook登录!);
NSLog(@欢迎屏幕我是%@,[[PFUser currentUser] username]);
}
}];
}
else {
// HERE
NSLog(@获取FB用户名%@时出错,[错误描述]);
}
[[PFUser currentUser] saveInBackground];
//回调 - 登录成功
if([delegate responsesToSelector:@selector(commsDidLogin :)]){
[delegate commsDidLogin:YES];
}
}];
}


解决方案

不是每个Facebook用户都暴露相同的信息作为其公开个人资料的一部分,电子邮件字段是您特别需要接受的情况,通常不会暴露。



您将收到的 userData NSDictionary只会填充人员公开的信息,因此根据用户需要处理丢失的密钥。



要阅读的文档:




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];
        }
    }];
}

解决方案

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:

这篇关于解析接收电子邮件FB SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆