我有这个代码,从FB样本(运行正常)复制,但在我的应用程序中只显示了一个朋友选择器的空白表。 Place 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];
}
项目:
我的餐桌(Place Picker)已满员。 我的桌子(朋友选择器)仍然是空的。我做错了什么?
答案 0 :(得分:1)
第1步:打开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
答案 1 :(得分:1)
在当前的文档中,Facebook无法解释您需要考虑的一些事项。
朋友选择器中显示的用户只是自己安装了应用的用户。这是较新的,可能在原始帖子时不适用。
您需要用户的user_friends权限才能看到任何朋友。
答案 2 :(得分:0)
根据最新的Facebook API(v 2.0),您无法直接选择好友列表。默认情况下,您只能访问三个权限,即email,public_profile和user_friends。
对于任何其他权限,您需要向Facebook询问(您可以从已创建应用程序的Facebook开发者帐户执行此操作)并阅读更改日志,因为在2014年4月30日或之后创建的应用程序再次无法访问旧API。
如果您在规定日期之前创建了应用,那么请使用旧的Facebook API(我建议使用3.13.1)并弃用功能( openActiveSessionWithPermissions )来创建FBSession。
我有同样的问题并且花了很长时间才弄明白。如果你有任何麻烦,请告诉我。
答案 3 :(得分:0)
确保您在用户注册上使用的权限数组包含user_friends
权限。如果您要复制代码,很容易错过。
NSArray *permissionsArray = @[ @"public_profile", @"user_friends"];
在注册时引用数组:
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
...
];
然后在FB开发人员仪表板中执行以下操作:
在您的应用上:
第二位用户应该可以在朋友列表中看到第一位用户。