Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user name and email id for Facebook SDK?

The code I have used

 if (FBSession.activeSession.state == FBSessionStateOpen
        || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {

        // Close the session and remove the access token from the cache
        // The session state handler (in the app delegate) will be called automatically
        [FBSession.activeSession closeAndClearTokenInformation];


        // If the session state is not any of the two "open" states when the button is clicked
    } else {
        // Open a session showing the user the login UI
        // You must ALWAYS ask for basic_info permissions when opening a session
        [FBSession openActiveSessionWithReadPermissions:@[@"basic_info,email"]
                                           allowLoginUI:YES
                                      completionHandler:
         ^(FBSession *session, FBSessionState state, NSError *error) {




             // Retrieve the app delegate
             AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
             // Call the app delegate's sessionStateChanged:state:error method to handle session state changes
             [appDelegate sessionStateChanged:session state:state error:error];
         }];
    }

from this code i need to get user name and mail id. if any one know the solution please help me thanks in advance.

like image 776
Peer Mohamed Thabib Avatar asked Feb 25 '14 09:02

Peer Mohamed Thabib


People also ask

How do I get my Facebook API user ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

How do I find my email for Facebook login?

Enter your password and click "Log In." Click the arrow in the upper-right corner of your news feed and select "Account Settings." Your email address is listed under General Account Settings.


1 Answers

  if ([FBSDKAccessToken currentAccessToken]) {
                     [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email,name,first_name"}]
                      startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                          if (!error) {
                              NSLog(@"fetched user:%@", result);
                               NSLog(@"%@",result[@"email"]);

                          }
                      }];


                 }
like image 160
Myaaoonn Avatar answered Sep 20 '22 06:09

Myaaoonn