2

我遵循了 Facebook Scruptious 示例,但在授权应用程序时遇到了问题。

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

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

    [FBSession.activeSession handleDidBecomeActive];
}

通过重试来处理失败的授权,但什么也没发生。

任何有关解决此问题的建议将不胜感激。

4

1 回答 1

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"];        
}

 }
于 2013-03-17T17:02:18.217 回答