Binding Parse and Facebook forces Facebook session to close

I am using Parse for my backend in my iOS app and I am trying to use FBLoginView

so that users can login with Facebook.

I am also trying to link their Facebook user account to their Parse account. When I try to link a user to their FB using

if (![PFFacebookUtils isLinkedWithUser:user]) {
    [PFFacebookUtils linkUser:user permissions:nil block:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"Woohoo, user logged in with Facebook!");
        }
    }];
}

      

I am getting a message that the Facebook session is not valid. I figured the above code seems to close the Facebook session (when I comment out the code, the session doesn't close) and gives me an error. Does anyone have experience with this error?

+3


source to share


2 answers


Do your other applications use Parse for the backend?

The custom state stored in PFFacebookUtils is different from the user returned from FBLoginView.

If your code looks like this:

#pragma mark FBLoginViewDelegate {
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user {

    // link current user
    NSLog(@"User: %@", user);

    if (![PFFacebookUtils isLinkedWithUser:user]) {
        [PFFacebookUtils linkUser:user permissions:nil block:^(BOOL succeeded, NSError *error) {
            if (succeeded) {
                NSLog(@"Woohoo, user logged in with Facebook!");
            }
        }];
    }
}

      



Then you are currently linking the Facebook user object to the PFUser, which are incompatible. I would suggest using the data returned by FBLoginView and creating a parsing user in the usual way:

#pragma mark FBLoginViewDelegate {
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {

    // link current user
    NSLog(@"User: %@", user);

    NSString *username = user[@"email"];
    NSString *password = user[@"id"];

    [PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {
        NSLog(@"User: %@", user);
        if (error.code == 101) {
            // sign up
            PFUser *user = [PFUser user];
            user.username = username;
            user.password = password;
            [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                NSLog(@"Error: %@", error);
            }];
        }
    }];
}

      

Now [PFUser currentUser] will return a custom parse object that was generated based on your Facebook login. If the application is uninstalled / reinstalled, then the next time the user logs into the application, FBLoginView will return the user ID that will be used to log in to the system for analysis as an existing user.

Edit: A similar issue I ran into is using FBLogin, PFFacebookUtils, and any other recent connections to facebook apps if my phone has Facebook embedded in iOS settings. It seems to have something to do with Apple's Facebook integration and the new Facebook SDKs. This is annoying, but currently I have to tell my users to remove their facebook information from settings, then they can login using either PFFacebookUtils or the process above. Hope this is resolved soon.

0


source


for the first part of your question, I found a way to log into my application just using Facebook with Parse. In fact, once users use this, you can check your application's data browser and check the auth data logged and the profile that was served with all the fb data I requested in the application.

here is the code i am using to login to fb did not associate the previous user with the fb account

 - (IBAction)loginButtonTouchHandler:(id)sender  {
// The permissions requested from the user
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];

// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
    //[_activityIndicator stopAnimating]; // Hide loading indicator

    if (!user) {
        if (!error) {
            NSLog(@"Uh oh. The user cancelled the Facebook login.");
        } else {
            NSLog(@"Uh oh. An error occurred: %@", error);
        }
    } else if (user.isNew) {
        NSLog(@"User with facebook signed up and logged in!");
        //Go to your next view

    } else {
        NSLog(@"User with facebook logged in!");
        //Go to your next view
    }
}];

      



}

Hope this helps!

-1


source







All Articles