【问题标题】:ViewController doesn`t display property FB/ParseViewController 不显示属性 FB/Parse
【发布时间】:2014-03-11 10:37:49
【问题描述】:

我正在使用 Parse,我想显示从 Parse 获取的电子邮件并显示在 Parse 的列中。 first_namelast_nameid 等所有内容都可以正常工作。但是当我尝试设置 prop.email 时,它没有找到任何属性。如果我在该位置(在代码中标记)执行相同的操作,它会发现我的电子邮件属性没有任何问题。

我的意思是这行代码:

[[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];
//This one doesn`t find property email
[[PFUser currentUser] setObject:prop.email forKey:@"email"];
[[PFUser currentUser] saveInBackground];

FB 连接的其余部分代码

{
    NSArray *permissionsArray = @[@"email"];
    [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;
                    [[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];
                    [[PFUser currentUser] setObject:prop.email forKey:@"email"];
                    [[PFUser currentUser] saveInBackground];
                 }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];
        }
    }];
}

【问题讨论】:

  • 你的错误信息是什么?
  • 你为什么要为每个属性调用保存?
  • Property 'email' not found on object of type 'NSDictionary&lt;FBGraphUser&gt; * ,只想显示名字、姓氏和电子邮件。我认为这是一个好方法,但只是 dont understand, why it doesnt 显示这个属性,而所有其他(用户名,first_name atc.)都显示没有任何问题
  • 您是否尝试过调试代码并查看调试器中的 prop 对象,看看它有什么值?
  • Thats that, if I set a breakpoint in the line with Dictionary, it doesnt 即使我点击按钮 facebook 并成功登录也会崩溃

标签: ios facebook parse-platform


【解决方案1】:

您的代码会产生编译错误,因为email 未在FBGraphUser 协议中定义。因此,您需要找到一种不同的方式从 Facebook 获取用户电子邮件。

如果您使用 PFSignUpViewController 并稍后链接帐户,请确保用户在该时间点输入电子邮件。

【讨论】:

  • 我不知道t use PFSignUpViewController, I made Log in/Sign up (Facebook, normal way) on my own. Isnt 还有其他方法可以从 FB 用户那里获取电子邮件吗?因为我不想重新制作我所有的代码。
  • 记录prop,邮件在那里,只是不是协议的一部分吗?
  • 有时区、性别、身份证等道具,但没有电子邮件。
  • Wain,现在我又在用 fb 登录了。协议不包含电子邮件道具。所以唯一的办法就是用 PFSignUpViewController 来做?
猜你喜欢
  • 2012-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-25
  • 2011-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多