Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors after PFUser logOut and PFFacebookUtils logInInBackgroundWithReadPermissions

I migrated my iOS code to FBSDK v4 + Parse 1.7.1 and I'm trying to handle the case of linking a user to a FB ID but it's already linked:

Another user is already linked to this facebook id. (Code: 208, Version: 1.7.1)

Everything seems to work fine after user logout and FB login but every time I alter or save the current user, or query a table, I get various errors such as:

Parse::UserCannotBeAlteredWithoutSessionError (Code: 206, Version: 1.7.1)

"PFKeychainStore" failed to set object for key 'currentUser'

no results matched the query (Code: 101, Version: 1.7.1)

Here is my code:

NSArray *permisions = [NSArray arrayWithObjects:@"public_profile", @"email", @"user_friends", nil];
[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissions block:^(BOOL succeeded, NSError *error) {

        if(succeeded && !error) {
            //... use data
        }
        else {
            if(error.code == 208) {
                [PFUser logOut];                   
                [PFFacebookUtils logInInBackgroundWithReadPermissions:permissions block:^(PFUser *user, NSError *error) {
                   //here I get a valid user and no error but...
                   //after this point the errors mentioned start to show up

                } 

            }
            else
                //... handle other errors
        }


    }];

I use Parse's automatic user until a user is linked to a FB account.

Would love some help about this, thanks!

like image 201
ronw Avatar asked Apr 18 '15 21:04

ronw


1 Answers

Adding becomeInBackground stopped the error:

NSArray *permisions = [NSArray arrayWithObjects:@"public_profile", @"email", @"user_friends", nil];
[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissions block:^(BOOL succeeded, NSError *error) {

    if(succeeded && !error) {
        //... success
    }
    else {
        if(error.code == kPFErrorFacebookAccountAlreadyLinked) {
            [PFUser logOutInBackgroundWithBlock:^(NSError *error) {
                if(!error) {
                    [PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissions block:^(BOOL succeeded, NSError *error) {
                        [PFUser becomeInBackground:[[PFUser currentUser] sessionToken] block:^(PFUser *user, NSError *error) {
                           if(user && !error) {
                                // ... success
                           }
                           else {
                               //... handle become error
                           }
                        }];
                     }];
                }
                else {
                    // ... handle bad logout
                }


        }
        else {
            //... handle other errors
        }
    }


}];
like image 200
ronw Avatar answered Nov 14 '22 21:11

ronw