Errors after PFUser logOut and PFFacebookUtils logInInBackgroundWithReadPermissions

I ported my iOS code to FBSDK v4 + Parse 1.7.1, and I'm trying to handle the case of a user binding with the FB ID, but it is already connected:

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

Everything seems to work well after logging out and logging in to FB, but every time I change or save the current user or query the 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 the automatic user Parse until the user is associated with an FB account.

I would like to help a little with this, thanks!

+6
source share
1 answer

Adding beInBackground 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 } } }]; 
+1
source

Source: https://habr.com/ru/post/985440/


All Articles