1

在我的项目中,用户通过 Facebook 本机应用程序(FBConnect)登录,我保留了用户的访问令牌。在我的应用程序中,我有一个类似按钮,它显示 facebookpage like 按钮的 iframe,现在当用户按下类似页面按钮时,facebook 要求用户再次登录。尽管用户当前已登录并且令牌有效并且我在 iframe 中传递访问令牌这是我用于创建 iframe 的代码。

NSString *str=[NSString stringWithFormat:@"<iframe src=\"https://www.facebook.com/plugins/likebox.php?id=XXXXXXXXXXXXXXX&access_token=%@&amp;width=292&amp;connections=0&amp;stream=false&amp;header=false&amp;height=62\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:282px; height:62px;\" allowTransparency=\"true\"></iframe>",accesstoken];
NSString *likeButtonHtml = [NSString stringWithFormat:@"<HTML><BODY>%@</BODY></HTML>", str];
  [webview loadHTMLString:likeButtonHtml baseURL:[NSURL URLWithString:@""]];

请告诉我如何避免第二次登录 iframe 上的类似页面

4

1 回答 1

1

您应该使用 UIWebView 登录。您可以使用实现方法来做到这一点:

[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
    switch (status) {
        case FBSessionStateOpen:
            // call the legacy session delegate
            //Now the session is open do corresponding UI changes
            break;
        case FBSessionStateClosedLoginFailed:
        { // prefer to keep decls near to their use

            // unpack the error code and reason in order to compute cancel bool
            NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
            NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
            BOOL userDidCancel = !errorCode && (!errorReason ||
                                                [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);

            // call the legacy session delegate if needed
            //[[delegate facebook] fbDialogNotLogin:userDidCancel];
        }
            break;
            // presently extension, log-out and invalidation are being implemented in the Facebook class
        default:
            break; // so we do nothing in response to those state transitions
    }
}];

检查我的示例代码:https ://github.com/gneil90/facebook-likebox-ios-login

于 2013-09-20T08:45:52.843 回答