任何人都可以帮助我。我无法弄清楚如何使用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];
}
我的名字很有价值,但是电子邮件和生日都是空的。
由于
答案 0 :(得分: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/