简体   繁体   中英

Parse.com - Update email for PFUser while using Fb authentication

I'm receiving PFUser properly while log in or sign up through Facebook. My permission array:

NSArray *permissionsArray = @[ @"user_about_me",@"email"];

In Parse Data browser, I can see that a user got created with some long string username and proper authData etc. But email field is still empty.

Do I need to make separate call to fill email field for the newly created PFUser ? If Yes then what are the proper steps.

Another question, how forgot password mechanism work for facebook authenticated user in Parse.com ? Do I need to fill email value first by calling graph api and then use that email address for forgot password feature ?

You need to make a separate call to fill the email attribute. Once the user is authenticated, you can call the startForMeWithCompletionHandler: method of FBRequestConnection class to get the user info and then save it to the current user. Your calls should look like this:

NSArray *permissionsArray = @[ @"user_about_me",@"email"];
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
    if (!error && user) {
        [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            if (!error) {
                [[PFUser currentUser] setObject:[result objectForKey:@"email"]
                                         forKey:@"email"];
                [[PFUser currentUser] saveInBackground];
            }
        }];
    }
}];

About the forgot password for Facebook users, it doesn't make sense since if the user forgot the password, it should change it on Facebook. But, if you call requestPasswordResetForEmail: method, it would send instructions for changing the password to the user since the email exists. Take into account that the logInWithUsername:password: uses the attribute username to log in the user, not the email, and that value it is probably unknown for Facebook users in your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM