4

我已经在我的应用程序中实现了 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];

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

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

    logout.title=@"Sign out";
    tabBarController.viewControllers=[NSArray arrayWithObjects:searchViewController,uprofile,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 和用户详细信息?成功登录 facebook 后,如何在选择第一个 tabitem(对应视图)的 tabbarcontroller 的情况下继续使用我的应用程序?

请帮我解决这个问题...请

4

1 回答 1

1

您需要设置 readPermissions 以获取此方法的电子邮件,方法是向它传递一个NSArray带有对象“email”。默认返回名称等剩余信息。

+ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions
                                allowLoginUI:(BOOL)allowLoginUI
                           completionHandler:(FBSessionStateHandler)handler;

facebook sdk 的。如果我没记错的话,除非指定的权限是“电子邮件”,否则用户字典的电子邮件对象是nil. 修改您的状态更改处理程序可能会请求用户详细信息,例如电子邮件。如果会话打开,则在sessionStateChanged:处理程序内部,您可以调用一个简单地执行此操作的方法

if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection,
           NSDictionary<FBGraphUser> *user,
           NSError *error) {
             if (!error) {
                 NSLog(@"%@", user);
                 NSLog(@"%@", [user objectForKey:@"email"]);

             }
         }];
    }
于 2013-02-01T07:42:53.130 回答