You should take a look at the Facebook docs here (there is a simple login example):
https://developers.facebook.com/docs/ios/ios-sdk-tutorial/authenticate/
In my opinion, I would use the SDK to register the login, you can do something like this:
/* Constants */ #define K_FACEBOOK_REQUEST_CREDENTIALSURL @"me/?fields=id,location,name,username,bio,picture,gender,website,birthday,email" #define K_FACEBOOK_PERMISSIONS @[@"user_about_me",@"user_birthday",@"email"] /* Facebook Keys */ #define K_FACEBOOK_REQUEST_ID @"id" #define K_FACEBOOK_REQUEST_USERNAME @"username" #define K_FACEBOOK_REQUEST_LOCATION @"location" #define K_FACEBOOK_REQUEST_FULLNAME @"name" #define K_FACEBOOK_REQUEST_BIO @"bio" #define K_FACEBOOK_REQUEST_WEBSITE @"website" #define K_FACEBOOK_REQUEST_EMAIL @"email" #define K_FACEBOOK_REQUEST_BIRTHDAY @"birthday" #define K_FACEBOOK_REQUEST_GENDER @"gender" - (void)initWithLoginFacebook { [PFFacebookUtils logInWithPermissions:K_FACEBOOK_PERMISSIONS block:^(PFUser *user, NSError *error) { if (!user) { if (!error) NSLog("ERROR_CAUSE_AUTH_USERCANCELLED"); else NSLog("ERROR_CAUSE_AUTH_FAILEDLOGIN"); } else if (user.isNew) { FBRequest *request = [FBRequest requestForMe]; [request startWithCompletionHandler:^(FBRequestConnection *connection,id result,NSError *error) { if (error) NSLog("ERROR_CAUSE_AUTH_FAILEDLOGIN"); else [self requestLoginFacebook:result]; }]; } else NSLog("User logged and not new!"); }]; } - (void)requestLoginFacebook:(id)result { NSDictionary *userData = (NSDictionary *)result; // Do something with the data... For example NSString *facebookId = userData[K_FACEBOOK_REQUEST_ID]; NSString *name = userData[K_FACEBOOK_REQUEST_FULLNAME]; NSString *username = [userData[K_FACEBOOK_REQUEST_USERNAME] lowercaseString]; NSString *bio = userData[K_FACEBOOK_REQUEST_BIO]; NSString *website = userData[K_FACEBOOK_REQUEST_WEBSITE]; NSString *location = userData[K_FACEBOOK_REQUEST_LOCATION][@"name"]; NSString *gender = userData[K_FACEBOOK_REQUEST_GENDER]; NSString *birthday = userData[K_FACEBOOK_REQUEST_BIRTHDAY]; NSString *email = userData[K_FACEBOOK_REQUEST_EMAIL]; NSString *profileImage = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=180&height=180",userData[@"id"]]; }
You must configure the SDK for Facebook in appDelegate and in the .plist file.
Your code will only work if the user has a Facebook account set in the deviceβs settings.
I am.
source share