问题
I'm having the following problem with the parse iOS SDK. In my app users can login using email (username)/password or facebook. When they use facebook the email (username) gets set automatically. But if the user logs in using email/password first and after logging out tries to login using facebook they get a duplicate account. My goal in this scenario is to link facebook to the previous account. Is there a way to check if the potential new user's email exist in parse database before creating a new account and if it exists then link both account? This way the user doesn't have to remember if they used facebook or email, they could use both seamlessly.
thanks.
回答1:
The basic logic you need here is as follows:
- Authenticate the user using Facebook
- Get the additional information you need--e.g., read email from the Facebook graph API, or (in my case) prompt the user for a phone number (which you cannot get from Facebook)
- Search the Parse user table for an account matching this piece of data (email address, phone number, etc.)
- If a match is found, and the user has authenticated against this identity*, link the accounts and login the user.
- If no match is found, create a new Parse account for the user, using the email/phone identity
It's outlined in more detail here: merge a user signed up by Facebook and already user signed up by email?. There's sample JS code but the idea should be the same for iOS.
*Pay close attention to what the Parser says in the last answer. If a Facebook user claims to own an email address or a phone number, you need to independently verify that they own that account (by e.g. sending an authorization link or code).
回答2:
You can do a simple query on the User table to see if a user already exists with the same username. If it does, you'll want to link the Facebook data to this account. Their docs outline how to do this with the SDK: https://parse.com/docs/ios_guide#fbusers-link/iOS
回答3:
It will link "user" with Facebook account easily.
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
[PFFacebookUtils linkUser:user permissions:permissionsArray block:^(BOOL succeeded, NSError *error) {
//do anything
}];
来源:https://stackoverflow.com/questions/19663807/parse-com-is-it-possible-to-login-using-facebook-while-checking-if-the-facebook