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]; }
项目:
- 只用一个视图制作一个全新的项目。
- 添加了2个button,并将其与动作连接起来。
- 复制/粘贴示例中的代码。
- 添加Facebook框架。
- 编辑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中没有得到很好的解释。
-
出现在朋友select器中的用户只是自己安装了应用程序的用户。 这是更新的,可能不适用于原来的职位。
-
您需要用户的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。
我有同样的问题,并花了很长时间才弄清楚。 让我知道如果你有任何麻烦。
-
确保用户注册时使用的权限数组包含
user_friends
权限。 如果你正在复制代码,很容易错过。NSArray *permissionsArray = @[ @"public_profile", @"user_friends"];
-
在注册时引用数组:
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) { ... ];
然后在FB开发人员仪表板中执行以下操作:
- 创build至less2个testing用户
- 将它们设置为彼此的朋友
并在您的应用程序:
- 让每个用户login并为您的应用程序提供权限(FB将只显示用户谁是朋友和使用应用程序)
第二个用户应该能够看到他们的朋友列表中的第一个用户。
- 如何获得Facebook页面的更大的个人资料图片
- 认识用户是否已经在iOS 6设置中定义了本地的Facebook帐户
- 有没有办法强制parse.com单设备login?
- iOS Facebook SDK错误域com.facebook.sdk代码2和代码7
- 完成处理程序的错误在Swift 3和Xcode 8中
- iOS Facebook获取用户的电子邮件
- 未find'FBSDKLoginKit / FBSDKLoginKit.h'文件(Facebook SDK for iOS v4.2&Xcode 7)
- iOS:Facebooklogin访问令牌错误:由于模拟器错误,从NSUserDefaults回落到加载访问令牌
- iOS中的链接器错误(体系结构x86_64的重复符号)