2

谁能帮我。我无法弄清楚如何使用适用于 iOS 的最新 Facebook SDK(v 3.1)进行单个 FQL 查询,以获取用户朋友的生日和电子邮件。当我查询名称等字段时,我得到正确的值,但电子邮件和生日字段为空。

这是我的代码

- (void)facebookViewControllerDoneWasPressed:(id)sender {

    // we pick up the users from the selection, and create a string that we use to update the text view
    // at the bottom of the display; note that self.selection is a property inherited from our base class
    for (id<FBGraphUser> user in _friendPickerController.selection) {
        _nameTxt.text = user.name;
        NSString *fql = [NSString stringWithFormat:@"SELECT email, birthday, name FROM user WHERE uid = %@ ",user.id];
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"q"];
        [FBRequestConnection startWithGraphPath:@"/fql"
                                     parameters:params
                                     HTTPMethod:@"GET"
                              completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                                      NSError *error) {
                                  if (error) {
                                      NSLog(@"Error: %@", [error localizedDescription]);
                                  } else {
                                      NSLog(@"Result: %@", result);
                                  }
                              }];

    }
    [self.navigationController dismissModalViewControllerAnimated:YES];
}

我得到了姓名的价值,但电子邮件和生日为空。

谢谢

4

1 回答 1

3

在调用查询之前,您需要让用户登录并请求电子邮件和 user_birthday 权限。例如:

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"email",
                        @"user_birthday",
                        nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                          allowLoginUI:allowLoginUI
                                     completionHandler:^(FBSession *session,
                                                     FBSessionState state,
                                                     NSError *error) {
                                     [self sessionStateChanged:session
                                                         state:state
                                                         error:error];
                                 }];
}

在本教程的上下文中使用了上述方法:

https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/

另请查看 FQL 教程:

https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/

于 2012-12-15T01:53:42.693 回答