【问题标题】:Facebook iOS SDK sometimes returns null for emailFacebook iOS SDK 有时会为电子邮件返回 null
【发布时间】:2013-09-10 17:25:54
【问题描述】:

我正在尝试通过我的应用程序登录来获取用户名、Facebook ID 和他们的电子邮件。以下是我的应用委托:

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI :(FBSessionStateHandler)handler{
    NSArray *permissions = [NSArray arrayWithObjects:@"basic_info", @"email", nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:allowLoginUI completionHandler:handler];
}

还有我的completionHandler 代码,一切都在这里:

void (^fbCompletionHandler)(FBSession *session, FBSessionState state, NSError *error) = ^(FBSession *session, FBSessionState state, NSError *error) {
    switch (state) {
        case FBSessionStateOpen:
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }

    if (error && [FBErrorUtility shouldNotifyUserForError:error]) {
        NSLog(@"%@", error.localizedDescription);
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:[FBErrorUtility userMessageForError:error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];

    }

    if (session.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
            if (!error) {
                [self performLoginOperation:user];
            }
        }];
    }
};

我正在访问用户的电子邮件,如下所示:[user objectForKey:@"email"]。大多数情况下它都有效,但我时不时地得到一个nil 值。我不知道为什么,因为我在权限中设置了它?还有其他原因吗?

我试图挖掘其他 SO 帖子,但找不到答案:

Facebook SDK email sometimes returns null - Android

Facebook SDK 3.0: how to receive user's e-mail?

PHP SDK 3.1.1 getUser() sometimes return 0

【问题讨论】:

    标签: facebook-ios-sdk


    【解决方案1】:

    我有类似的情况,用户对象不包含响应的电子邮件。我的情况是用户电子邮件地址实际上正在等待验证。在https://developers.facebook.com/docs/reference/api/user/ 的 Facebook 图形 API 文档中,对于电子邮件字段,它声明:

    注意:如果用户没有可用的有效电子邮件地址,则不会返回此字段

    看看这是否也是你遇到问题的原因。

    【讨论】:

    • 它所说的有时无效的事实是一个非常重要的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多