0

I followed a little 'guides online, but I can not figure out how to get the username of the user such as Facebook. The login and session work properly. But I can not just take the values โ€‹โ€‹of the current user. This is the working code

 if (!appDelegate.session.isOpen) {
    // create a fresh session object
    appDelegate.session = [[FBSession alloc] init];

    // if we don't have a cached token, a call to open here would cause UX for login to
    // occur; we don't want that to happen unless the user clicks the login button, and so
    // we check here to make sure we have a token before calling open
    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
        // even though we had a cached token, we need to login to make the session usable
        [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {



            NSLog(@"SESSION FACEBOOK OK");

           // how i get username ?

Thanks in advance

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Delir
  • 55
  • 7

1 Answers1

1

Learn how to use the Facebook Graph API.

To request the user info:

[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
   if (!error) {
      // Success! Include your code to handle the results here
      NSLog(@"user info: %@", result);
   }  else {
      // An error occurred, we need to handle the error
      // See: https://developers.facebook.com/docs/ios/errors   
   }
}];
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • I have tried this but still the session is active the code does not enter the if ... โ€“ Delir Mar 24 '14 at 16:37
  • Please follow the code from the link step by step, you'll get that. Give some time and try; and if you find any difficulty then let me know โ€“ Sahil Mittal Mar 24 '14 at 16:47