Facebook登录失败

时间:2013-02-15 08:00:47

标签: ios facebook

我遵循Facebook Scruptious示例并且在授权应用时遇到问题。

当我运行应用程序并且用户登录到本机Facebook应用程序时,应用程序的授权完美运行 - 用户被带到本机应用程序,授权并返回到应用程序。但是,如果用户未登录Facebook应用程序,则会要求他登录,但不会请求授权,并且用户仍在Facebook应用程序中。问题: 1.这是一个FB错误,有没有办法解决它? 2.我按下主页按钮再次打开应用程序 - 我预计

- (void)applicationDidBecomeActive:(UIApplication *)application {

    [FBSession.activeSession handleDidBecomeActive];
}

通过重试来处理失败的授权,但没有任何反应。

对于解决这个问题的任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我认为您在创建会话(登录)

后缺少更新

你有这样的事情:

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
    // if a user logs out explicitly, we delete any cached token information, and next
    // time they run the applicaiton they will be presented with log in UX again; most
    // users will simply close the app or switch away, without logging out; this will
    // cause the implicit cached-token login to occur on next launch of the application
    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        appDelegate.session = [[FBSession alloc] init];
    }

    // if the session isn't open, let's open it now and present the login UX to the user
    [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                                                     FBSessionState status, 
                                                     NSError *error) {
        // and here we make sure to update our UX according to the new session state
        [self updateView];
    }];
} 

请记住这样做[self updateView];

假设你的 UpdateView 是这样的:

- (void)updateView {
// get the app delegate, so that we can reference the session property
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {        
    // valid account UI is shown whenever the session is open
    [self.buttonLoginLogout setTitle:@"Log out" forState:UIControlStateNormal];        
    [self.textNoteOrLink setText:[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@", appDelegate.session.accessTokenData.accessToken]];

    [self performSegueWithIdentifier:@"inicio" sender:self];
} else {        
    // login-needed account UI is shown whenever the session is closed
    [self.buttonLoginLogout setTitle:@"Log in" forState:UIControlStateNormal];        
    [self.textNoteOrLink setText:@"Login to create a link to fetch account data"];        
}

 }