14

我正在使用电子邮件权限打开 facebook 会话,如下所示:

- (void)facebookOpenSession {
    NSArray *permissions = @[@"email"];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
        [self sessionStateChanged:session state:state error:error];
    }];
}

然后会话状态的重要片段更改如下所示:

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error {
    switch (state) {
        case FBSessionStateOpen: {
            [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
             if (error) {
                //error
             } else {
                 self.myFirstNameLabel.text = user.first_name;
                 self.myLastNameLabel.text = user.last_name;
                 // self.myEmailLabel.text = @"";
             }
         }];
    }
    ...

我如何实际提取用户的电子邮件?它是在提供的变量之一中,还是我必须在完成处理程序中进行另一个调用?

提前致谢!

4

2 回答 2

26

FBGraphUser 没有该属性(我假设是因为它是可选的/仅在您要求电子邮件权限时才可用)但您仍然应该能够从字典中访问它,如下所示:

[user objectForKey:@"email"]
于 2012-11-21T00:23:37.053 回答
0

您应该在询问正确的权限之前检查

loginView.readPermissions = @[@"public_profile", @"email"];
于 2014-08-28T16:28:12.873 回答