使用ios6从xcode 4.5中的facebook获取用户详细信息

时间:2012-12-14 15:54:56

标签: iphone objective-c ios xcode facebook-login

我在我的应用程序中实现了facebook登录集成的概念。 1 ---->我能够登录facebook登录,但在用户登录后我想继续使用我的应用程序,即出现三个标签项的tabbarController,同时我需要获取facebook用户详细信息(电子邮件,名字,姓氏等)

但我无法检索细节。我不明白我哪里出错了。

在我的ViewController.m中:

- (IBAction)performLogin:(id)sender
{
    AppAppDelegate *appDelegate = (AppAppDelegate *) [[UIApplication sharedApplication] delegate];

    [appDelegate openSessionWithAllowLoginUI:YES];

    UITabBarController *tabBarController=[[UITabBarController alloc]init];
    SearchViewController *searchViewController=[[SearchViewController alloc]initWithNibName:@"SearchViewController" bundle:nil];

    UserProfile *userprofile=[[UserProfile alloc]initWithNibName:@"UserProfile" bundle:nil];
    userprofile.title=@"My Profile";

    LogOut *logout=[[LogOut alloc]initWithNibName:@"LogOut" bundle:nil];

    logout.title=@"Log Out";
    tabBarController.viewControllers=[NSArray arrayWithObjects:searchViewController,userprofile,logout, nil];

    [self presentModalViewController:tabBarController animated:YES];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(sessionStateChanged:)
                                                 name:FBSessionStateChangedNotification
                                               object:nil];
}

- (void)sessionStateChanged:(NSNotification*)notification {

    if (FBSession.activeSession.isOpen) {

        [FBRequestConnection
         startForMeWithCompletionHandler:^(FBRequestConnection *connection,
                                           id<FBGraphUser> user,
                                           NSError *error) {
             if (!error) {
                 NSString *fbUserEmail= @"";

                 NSLog(@"%@",user);

                 fbUserEmail=[user objectForKey:@"email"];

                 AppAppDelegate *appDelegate = (AppAppDelegate *) [[UIApplication sharedApplication] delegate];

                 appDelegate.fbEmail=fbUserEmail;
             }
         }
         ];
    }
}

但是这里没有显示facebook登录页面我得到tabbarController而我无法获取用户详细信息。

如何首先显示facebook登录页面,然后使用tabbarController显示用户详细信息。

1 个答案:

答案 0 :(得分:4)

您可以使用Facebook Graph API获取Facebook用户详细信息,下面链接演示使用Graph API获取基本用户详细信息。点击此处:http://www.raywenderlich.com/1578/how-to-get-a-user-profile-with-facebooks-new-graph-api-from-your-iphone-app