8

I encountered a facebook login problem. I installed FB SDK 3.0 and sample projects seemly run well --- not quite sure though. When I create a button in my own project and try to log in to Facebook, I always get FBSessionStateClosedLoginFailed from sessionStateChanged method, although I apparently get the page "You have already authorized this app. Press Okay to continue". I also tried log out through Simulator Safari facebook page, and re-launched my project and I got new username/password page and I then logged in, but I still get FBSessionStateClosedLoginFailed!

A few more observations. 1, I got FBSessionStateClosedLoginFailed thru NSLog, the log comes up right after I clicked Okay button on the Facebook page "You have already authorized this app. 2, I tried clean xcode project cache, but no help.

Kind of frustrated. I wonder if any of you can help on this problem. Appreciated! -Tony

Addition: I did a bit more research, and I found what I have is probably a typical problem, as Facebook highlight here ("Pro-tip 3: Complete all iOS App Settings" section in page http://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/). The image with a big red cross over iPhone is exactly what I have. From xcode project, I click my login button, and I'm directed to this page, and every time I have to click "Okay" on this page (let me call it Okay_page) to go back to my app in Simulator, however with login status as FBSessionStateClosedLoginFailed. I checked bundle ID, I have it correct. I don't have a 'YOUR_IPHONE_APP_STORE_ID' yet, which I believe I need pay Apple to get and I will do it later but not while I'm still working on it.

Now get a couple of questions: 1, Do I have to have YOUR_IPHONE_APP_STORE_ID to skip this Okay_page? 2, Does this (not automatically re-directed back to my app from this Okay_page) have anything to do with that I always get a login status of FBSessionStateClosedLoginFailed when I manually click Okay in this Okay_page and return to my app in Simulator? In another word, is (that I have to manually click Okay to get back to my app in Simulator) (the reason I got a status of FBSessionStateClosedLoginFailed)?

2
  • 1
    hey how did you fix this problem
    – Iqbal Khan
    Feb 14, 2013 at 10:28
  • I was having this same problem and i fixed. check my answer
    – Iqbal Khan
    Feb 14, 2013 at 10:33

8 Answers 8

27

Did you have set this function in AppDelegate?

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [FBSession.activeSession handleOpenURL:url];
}
1
  • I miss this every time I integrate Facebook. First time with the new SDK though. Dec 3, 2012 at 12:26
8

I had the same issue:

  1. We created the facebook app (developer.facebook.com) setting our bundle id (ex. com.MyCompany.MyApp)
  2. Off course, created our iOS app with the same bundle id
  3. After delivered our app to the client, he changed the bundle id without notify us.

Obviously he started to get FBSessionStateClosedLoginFailed errors!

So, you probably have different bundle id's between your iOS project and your Facebook App.

7

I had this error and couldn't resolve it for quite some time. It turns out that if you are using the native iOS Facebook account in settings and choose "no" for allow Facebook for this app, the app is blocked by the OS. You will always get the FBSessionStateClosedLoginFailed error and there is nothing you can do inside the code to fix this (99% sure). The best you can do is alert the user to check out the settings.

4

i am typing wrong line in given below method. self.session was nil

return [self.session handleOpenURL:url];

it should be

return  [[FBSession activeSession] handleOpenURL:url];

Use Following Method.

- (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication
             annotation:(id)annotation {
        // attempt to extract a token from the url
      return  [[FBSession activeSession] handleOpenURL:url];
        // return [self.session handleOpenURL:url];
    }
1
  • Thank you for this answer man, i have an universal app that was working on iphone but not on ipad, and this was the reason. I can't explain why on ipad the session was nil though. May 8, 2013 at 19:59
2

I fixed this problem after I reset the simulator. iOS Simulator - Reset Content and Settings..., hope to help.

1
  • 2
    Thanks, but I have no luck on your suggestions. I still see failure status right after I click login button, (and then I get to the "you have already authorized ..." page,) and right after I click Okay on the already-authorized page. In another word, I could log in, but the status is FBSessionStateClosedLoginFailed.
    – Tony Xu
    Aug 21, 2012 at 5:40
1

I had this issue because I was calling [FBSession.activeSession close] in my applicationDidEnterBackground: app delegate callback. This closed the session so that when the redirect brought the app back up to open the session, it failed because it had been put into the closed state.

Make sure that you're not closing the session anywhere before you get to the Okay page.

1

go to Facebook.com. Open your application on the left panel -> Status & Review -> there is a toggle with text "Do you want to make this app and all its live features available to the general public?". Turn it on

Status & Review page

0

well. I followed FBLoginCustomUISample somewhere on github.com and it was a working example of facebook login implementation from facebook itself. You can also read my workaround while creating facebook login feature in a iOS app. Here is a link form me:

Native iOS Facebook SSO won't return to app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.