32

I have just update both my Parse and Facebook SDK's (1.7.1 and 4.0 respectively) - both were an absolute pain to get working I might add!

However I now getting 209 errors when I try to log in with Facebook.

Here's an example of my code:

- (void)loginWithFacebook:(HMSuccessBlock)completion{
NSArray *permissionsArray = @[@"user_about_me",@"user_location",@"user_friends",@"user_relationships"];

// Login PFUser using Facebook

[PFFacebookUtils logInInBackgroundWithReadPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
    if (!user) {
        NSLog(@"Uh oh. The user cancelled the Facebook login.");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error"
                                                        message:error.localizedDescription
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"Dismiss", nil];
        [alert show];
        completion(NO, error);

    } else if (user.isNew) {
        NSLog(@"User signed up and logged in through Facebook!");
        if (completion) {
            completion(YES, nil);
        }
    } else {
        NSLog(@"User logged in through Facebook!");
           completion(YES, nil);
    }
}];
}

Which yeilds the following [Error]: invalid session token (Code: 209, Version: 1.7.1)

My initial thinking is that the issue is something to do with my code in the app delegate - on older versions of the facebooksdk I would apply the following code

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
              sourceApplication:sourceApplication
                    withSession:[PFFacebookUtils session]];
}

However I cant seem to find anything to replicate this in the updated version, hence my code being

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                      openURL:url
                                            sourceApplication:sourceApplication
                                                   annotation:annotation];
}

Any help would be greatly appreciated.

Kerberos
  • 4,036
  • 3
  • 36
  • 55
user499846
  • 681
  • 3
  • 11
  • 24
  • 2
    This is now an accepted bug by Facebook Parse Eng team https://developers.facebook.com/bugs/756392341145634/ – CPD Apr 29 '15 at 15:42

5 Answers5

33

Delete the app from the simulator or your phone, then rebuild and re-run the app. Sometimes an old token gets cached. I just solved this problem for my app.

Don Alejandro
  • 885
  • 1
  • 7
  • 16
TheRealRonDez
  • 2,807
  • 2
  • 30
  • 40
18

Check out this page: https://parse.com/tutorials/session-migration-tutorial

Most likely your app was using legacy session tokens. You can migrate to revocable session tokens by adding this to your app delegate right after you set the app id and client key.

    [PFUser enableRevocableSessionInBackground];

Parse's website has a section on handling this error that might be of more help to you: https://www.parse.com/docs/ios_guide#sessions-handleerror/iOS

  • 1
    I had the same issue. When this happens, it won't allow you to make ANY calls to parse until the user is logged in. You have to disable Revocable Accounts and then call ParseUser.LoginAsync(username, pass); After I logged in, I removed the code and it could make calls to parse before the user is logged in again. – Levi Fuller Aug 02 '15 at 01:52
  • This worked for me --> PFUser.enableRevocableSessionInBackground() – Jay Dec 30 '16 at 01:14
7

Some of the answers posted were temporary fixes - however the problem could reoccur later if a user logged out and tried to log back in again - I think this was due to me allowing anonymous users also - the only way I could clear it is to call [pfuser logout] prior to log in

user499846
  • 681
  • 3
  • 11
  • 24
2

I think there some more steps need to be followed:

  1. You have to add [FBSDKAppEvents activateApp] in applicationDidBecomeActive.

  2. You should write
    return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; in method didFinishLaunchingWithOptions in AppDelegate.

Trying above steps should work for you.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
R_Developer
  • 864
  • 1
  • 7
  • 10
1

With revocable sessions, your current session token could become invalid if its corresponding Session object is deleted from the Parse Cloud. This could happen if you implement a Session Manager UI that lets users log out of other devices, or if you manually delete the session via Cloud Code, REST API, or Data Browser. Sessions could also be deleted due to automatic expiration (if configured in app settings). When a device’s session token no longer corresponds to a Session object on the Parse Cloud, all API requests from that device will fail with “Error 209: invalid session token”.

Yogesh Bangar
  • 480
  • 4
  • 12