developer
developer

Reputation: 658

facebook sdk ios get user information

I'm using facebook sdk 3.0, however I'm facing difficulties when I'm trying to get user's information like email etc.

My Code:

- (IBAction)fbLogin:(id)sender {

    [self facebookLogin];
}

-(void) facebookLogin
{

[FBSession openActiveSessionWithReadPermissions:@[@"email"]
   allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
  switch (state) {
      case FBSessionStateOpen:
          [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
              if (error) {
              }
              else {
                  name = [FBuser name];
                  email = [FBuser objectForKey:@"email"];
                  pic = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser objectID]];  
              }
          }];
          [self checkUser];
          break;
  }
}];
}

My code opens the Facebook login, and ask for authorisation but after that It returns to my app showing/geting nothing with that. I diagnose through break points and found that after the line switch (state) it simply exits without giving any information.

My Question is, how can I fetch user's email via facebook sdk 3.0.

Upvotes: 0

Views: 70

Answers (1)

M.Alatrash
M.Alatrash

Reputation: 1265

add the below to app delegate:

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
        return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];

}

don't forget to import the header:

#import "FacebookSDK.h"

Upvotes: 1

Related Questions