The answer to yourself is good. For more information, you can use the custom facebook button, and you can call up the fetch data when the access token actually receives the login process.
Log in using the custom button and access token.
Get user information on facebook sdk 4.x
Swift
@IBAction func btnFBLoginPressed(sender: AnyObject) { var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager .logInWithReadPermissions(["email"], handler: { (result, error) -> Void in if (error == nil){ var fbloginresult : FBSDKLoginManagerLoginResult = result if(fbloginresult.grantedPermissions.containsObject("email")) { self.getFBUserData() fbLoginManager.logOut() } } }) } func getFBUserData(){ if((FBSDKAccessToken.currentAccessToken()) != nil){ FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in if (error == nil){ println(result) } }) } }
Exit:
{ email = " ashishkakkad8@gmai l.com"; "first_name" = Ashish; id = 910855688971343; "last_name" = Kakkad; name = "Ashish Kakkad"; picture = { data = { "is_silhouette" = 0; url = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/10394859_900936369963275_5557870055628103117_n.jpg?oh=fefbfca1272966fc78286c36741f9ac6&oe=55C89225&__gda__=1438608579_9133f15e55b594f6ac2306d61fa6b6b3"; }; }; }
Objective-c
Sign in with Facebook SDK 4.x
Add the following code to the facebook login button:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Error } else if (result.isCancelled) { // Cancelled } else { if ([result.grantedPermissions containsObject:@"email"]) { [self getFBResult]; } } }];
Get Facebook Results Method:
-(void)getFBResult { if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, picture.type(large), email"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"fb user info : %@",result); } else { NSLog(@"error : %@",error); } }]; } }
You can change the permission fields as you want.