我是 iOS 开发的新手。使用 Facebook SDK 从 facebook 获取朋友时出现错误。这是我的代码。
脸书课堂
- (void)fetchFacebookFriend{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_birthday",@"friends_hometown",
@"friends_birthday",@"friends_location",@"friends_work_history",
nil];
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error != nil) {
NSLog(@"Failed to retrive facebook friend.");
return;
}
else{
self.myArray = [[NSMutableArray alloc] init];
NSLog(@"permissions::%@",FBSession.activeSession.permissions);
FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,picture,birthday,hometown,location,work"];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
appDelegate.myFacebookArray = [[NSMutableArray alloc] init];
for (NSDictionary *fbData in [result objectForKey:@"data"]) {
NSLog(@"%@",fbData);
[self.myArray addObject:fbData];
}
}];
}
}];
return;
}
}
视图控制器
- (IBAction)pickFriendPressed:(id)sender {
NSLog(@"##Begin");
[[FacebookClass sharedInstance] fetchFacebookFriend];
NSLog(@"##End");
}
输出
##Begin
##End
Json data
请帮助我在显示 ##End 后获取 Json 数据。谢谢