FBFriendPickerViewController在iOS上显示和清空表格。 放置选取器运行良好

我有这个代码,从FB样本(它运行良好)复制,但在我的应用程序显示只是一个空表为朋友选取器。 地方select器运行良好,显示一个完整的表格。

Friend Picker有什么不对?

在AppDelegate中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [FBFriendPickerViewController class]; [FBPlacePickerViewController class]; return YES; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication]; } 

在视图控制器中:

 - (IBAction)pickFriendsButtonClick:(id)sender { // FBSample logic // if the session is open, then load the data for our view controller if (!FBSession.activeSession.isOpen) { // if the session is closed, then we open it here, and establish a handler for state changes [FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { if (error) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } else if (session.isOpen) { [self pickFriendsButtonClick:sender]; } }]; return; } // Create friend picker, and get data loaded into it. FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init]; friendPickerController.title = @"Pick Friends"; friendPickerController.delegate = self; [friendPickerController loadData]; [friendPickerController presentModallyFromViewController:self animated:YES handler:nil]; } - (IBAction)pickPlacesButtonClick:(id)sender{ // FBSample logic // if the session is open, then load the data for our view controller if (!FBSession.activeSession.isOpen) { // if the session is closed, then we open it here, and establish a handler for state changes [FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { if (error) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } else if (session.isOpen) { [self pickPlacesButtonClick:sender]; } }]; return; } // Initialize the place picker FBPlacePickerViewController *placePickerController = [[FBPlacePickerViewController alloc] init]; // Set the place picker title placePickerController.title = @"Pick Place"; // Hard code current location to Menlo Park, CA placePickerController.locationCoordinate = CLLocationCoordinate2DMake(37.453827, -122.182187); // Configure the additional search parameters placePickerController.radiusInMeters = 1000; placePickerController.resultsLimit = 50; placePickerController.searchText = @"restaurant"; placePickerController.delegate = self; // Load the place data [placePickerController loadData]; // Show the place picker modally [placePickerController presentModallyFromViewController:self animated:YES handler:nil]; } - (void)facebookViewControllerDoneWasPressed:(id)sender { NSLog(@"Done pressed"); [self dismissViewControllerAnimated:YES completion:NULL]; } - (void)facebookViewControllerCancelWasPressed:(id)sender { NSLog(@"Cancel pressed"); [self dismissViewControllerAnimated:YES completion:NULL]; } 

项目:

  1. 只用一个视图制作一个全新的项目。
  2. 添加了2个button,并将其与动作连接起来。
  3. 复制/粘贴示例中的代码。
  4. 添加Facebook框架。
  5. 编辑plist文件以添加Facebook应用程序编号。

我的桌子(地方select器)已满餐厅。 我的桌子(Friend Picker)仍然是空的。 我究竟做错了什么?

第一步:打开Facebook会话,如果不存在

 if ( !FBSession.activeSession.isOpen ) { [FBSession openActiveSessionWithPermissions:@[@"public_profile", @"email", @"user_friends" ] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }]; } 

第2步:请求获取好友列表(包括必填字段)

 FBRequest* friendsRequest = [FBRequest requestWithGraphPath:@"me/friends?fields=picture,name,username,location,first_name,last_name" parameters:nil HTTPMethod:@"GET"]; [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary* result, NSError *error) { //store result into facebookFriendsArray self.facebookFriendsArray = [result objectForKey:@"data"]; }]; 

第3步:从facebookFriendsArray重新加载数据到tableView

在当前的文档中,您需要考虑的一些事情在Facebook中没有得到很好的解释。

  1. 出现在朋友select器中的用户只是自己安装了应用程序的用户。 这是更新的,可能不适用于原来的职位。

  2. 您需要用户的user_friends权限才能看到任何朋友。

更多在这里: Facebook的iOSselect朋友表空白

根据最新的Facebook API(v 2.0),你不能直接select朋友列表。 默认情况下,您只能访问三个权限,即email,public_profile和user_friends。

对于任何额外的许可,您需要询问Facebook(您可以从创build应用程序的Facebook开发人员帐户中执行此操作),并阅读更改日志,因为2014年4月30日或之后创build的应用程序无法访问旧API。

如果你在规定的date之前创build了应用程序,那么使用旧的Facebook API(我推荐3.13.1)和不推荐使用的函数( openActiveSessionWithPermissions )来创buildFBSession。

我有同样的问题,并花了很长时间才弄清楚。 让我知道如果你有任何麻烦。

  1. 确保用户注册时使用的权限数组包含user_friends权限。 如果你正在复制代码,很容易错过。

     NSArray *permissionsArray = @[ @"public_profile", @"user_friends"]; 
  2. 在注册时引用数组:

     [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) { ... ]; 

然后在FB开发人员仪表板中执行以下操作:

  1. 创build至less2个testing用户
  2. 将它们设置为彼此的朋友

并在您的应用程序:

  1. 让每个用户login并为您的应用程序提供权限(FB将只显示用户谁是朋友和使用应用程序)

第二个用户应该能够看到他们的朋友列表中的第一个用户。