0

I am not able to retrieve EMailID's from Facebook Users.I am Getting permission for email and logging for verification as is it working.But it is not working.i am not sure where i have gone wrong.struggling for long time.Can any one please help me out. Below is my Code.Thanks in Advance.

-(IBAction)btnClicked{
  // Initialize a session object
  FBSession *session = [[FBSession alloc] init];
  // Set the active session
  [FBSession setActiveSession:session];
  // Open the session
  [session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView
        completionHandler:^(FBSession *session,
                            FBSessionState status,
                            NSError *error) {
           // Respond to session state changes,
            // ex: updating the view
            if ([session isOpen]) {
                // Session is open
                NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
                [FBSession openActiveSessionWithReadPermissions:permissions
                                                   allowLoginUI:NO
                                              completionHandler:
                 ^(FBSession *session,
                   FBSessionState state, NSError *error) {

                     [self sessionStateChanged:session state:state error:error];
                 }];
                NSLog(@"Session is open");
                [self populateDetails];

            } else {
                // Session is closed
                NSLog(@"Session is closed");
            }
        }];
}
-(void)populateDetails{
    if (FBSession.activeSession.isOpen) {

    [[FBRequest requestForMe]startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary<FBGraphUser> *user,  NSError *error) {
        if(!error){

            NSLog(@"email %@",[user objectForKey:@"email"]);
    }
    else
    {
        NSLog(@"NW Issue");
    }
  }
}
Unheilig
  • 16,196
  • 193
  • 68
  • 98
Grey Code
  • 326
  • 5
  • 19

2 Answers2

1

Check this one

if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
             if (!error) {
                 self.nameLabel.text = user.name;
                 self.emailLabel.text = [user objectForKey:@"email"];
             }
         }];
    }




NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
 ^(FBSession *session, FBSessionState state, NSError *error) {
     [self facebookSessionStateChanged:session state:state error:error];
 }];
Bajaj
  • 859
  • 7
  • 17
  • No Known class method for selector "sessionOpenWithPermissions:" – Grey Code Oct 08 '13 at 08:34
  • http://stackoverflow.com/questions/11877398/new-facebook-sdk-fbsession-sessionopenwithpermissions check it – Bajaj Oct 08 '13 at 09:24
  • dude call this method openActiveSessionWithReadPermissions check abouve tutorials – Bajaj Oct 08 '13 at 09:26
  • gotit.if i am using allowLoginUI:YES its fetching.as it is NO it is not fetching.But if i use allowLoginUI:YES ,its asking FB Login UI again after LogingIn.howcan i solve this ? – Grey Code Oct 08 '13 at 09:50
  • FBLogin attemps twice.but im using single session only.how is it possible ? – Grey Code Oct 08 '13 at 10:00
  • you can check method cz i think you can call login method two times – Bajaj Oct 08 '13 at 10:19
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/38777/discussion-between-bajaj-and-grey-code) – Bajaj Oct 08 '13 at 10:52
0

i think you have to try this one

` self.fbGraph = [[FbGraph alloc] initWithFbClientID:kFacebookAppId]; if ( (fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0) )

    {
       
        [fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)
         
                             andExtendedPermissions:CFacebookPermissions];
        
    }

else

    {
        
        [self performSelector:@selector(fbGraphCallback:) withObject:nil afterDelay:0.000000000001];
        
    }

`

and for permisson set this

define CFacebookPermissions @"publish_stream,offline_access,user_checkins,friends_checkins,read_stream,email"

Community
  • 1
  • 1
iKambad
  • 351
  • 1
  • 2
  • 13