在我的iPhone应用程序中,我正在使用facebook sdk 3.1。我想首先重定向facebook登录页面。登录后再次重定向到我的应用程序。
当我没有在iphone的设置中登录facebook时,我也希望从friendspickercontroller获取facebook好友列表。
我正在使用此代码
Facebook登录:
-(IBAction)facebookButtonPressed:(id)sender
{
NSLog(@" hi im ");
NSArray *permissions =
[NSArray arrayWithObjects:@"user_photos", @"friends_photos",@"email", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
if(!error)
{
NSLog(@" hi im sucessfully lloged in");
[self sessionStateChanged:session state:state error:error];
}
}];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
{
UIViewController *topViewController =
[appDelegate.naviCon topViewController];
if ([[topViewController modalViewController]
isKindOfClass:[ViewController class]]) {
[topViewController dismissModalViewControllerAnimated:YES];
}
NSLog(@"h im in state open 1111111");
{
NSLog(@"hi iam in open state9999999999999999999");
}
}
break;
case FBSessionStateClosed:
{
NSLog(@"iam in loginfailed 444444444444");
}
case FBSessionStateClosedLoginFailed:
NSLog(@"iam in loginfailed 555555555555");
NSLog(@"iam in statecloze 555555555555");
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error)
{
}
}
得到炒菜:
NSArray *permissions =
[NSArray arrayWithObjects:@"user_photos", @"friends_photos",@"email", nil];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error)
{
if(!error)
{
if (self.friendPickerController == nil)
{
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = @"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
//[self.friendPickerController clearSelection];
[self presentModalViewController:self.friendPickerController animated:YES];
}
}];
}
提前致谢
答案 0 :(得分:1)
您还需要read_friendlists获取朋友列表的权限。
然后使用
-(void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker
{
NSArray *friends = friendPicker.selection;
}
由于
答案 1 :(得分:0)
- (void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker
{
NSArray *friends = friendPicker.selection;
}
我希望这就是你要找的东西!