1

In my project user get logged-in through Facebook native app(FBConnect) and i kept the user's access token. In my app i have a like button which display the iframe of a facebookpage like button and now when user press the page like button the facebook ask the user to sign in again. Although the user is currently logged-in and the token is validand i am passing the access token in the iframe Here is the code which i am using for creating 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:@""]];

Please tell me how will i avoid this second login for like a page on iframe

prakhar
  • 828
  • 7
  • 18
  • Where is the code? And if this is a question about iframes, then why is question tagged "iOS" and "Objective-C"? – Mick MacCallum Aug 27 '12 at 14:39
  • I have exactly same problem as you but with Android. But the answer will be almost the same:http://stackoverflow.com/questions/12464570/facebook-like-button-in-webview-with-sdk – Warlock Sep 20 '12 at 11:37

1 Answers1

1

You should log in with UIWebView. You can do it with implementing method:

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

Check my sample code:https://github.com/gneil90/facebook-likebox-ios-login

Neil Galiaskarov
  • 5,015
  • 2
  • 27
  • 46