2

I'm using Facebook SDK v.3.18.2

I only wants user's first name, last name, email and date of birth, I'm getting everything except date of birth.

I'm surely doing wrong with the permission? Not sure.

Here's some code to help you find out my problem,

    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"] allowLoginUI:YES completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
         // Call the sessionStateChanged:state:error method to handle session state changes
         [self sessionStateChanged:session state:state error:error];
     }];

// This method will handle ALL the session state changes in the app
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError     *)error
{
    // If the session was opened successfully
    if (!error && state == FBSessionStateOpen){
        NSLog(@"Session opened");
        if (FBSession.activeSession.isOpen) {

//            This is not working though I'm putting it as comment
//            [[FBRequest requestForMe] startWithCompletionHandler:
//             ^(FBRequestConnection *connection,
//               NSDictionary<FBGraphUser> *user,
//               NSError *error) {
//                 if (!error) {
//                     NSLog(@"User Info : %@",user);
//                 }
//             }];
        
        [[FBRequest requestForGraphPath:@"me"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            NSLog(@"%@",result);
        }];
    }
    return;
}

Here's Output Log:

{
    email = "email@domain";
    "first_name" = Hemang;
    gender = male;
    id = someId;
    "last_name" = Shah;
    link = "https://www.facebook.com/app_scoped_user_id/someId/";
    locale = "en_US";
    name = "Hemang Shah";
    timezone = "5.5";
    "updated_time" = "some date and time";
    verified = 1;
}

But date of birth is missing, I've it set in my profile too.

Update:

Tried with the following permissions NOT WORKED!

"user_birthdate" or "birthday"

Community
  • 1
  • 1
Hemang
  • 26,840
  • 19
  • 119
  • 186

2 Answers2

2
 [FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_birthday",@"public_profile"]
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

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

                                                  NSLog(@"error:%@",error);


                                              }
                                              else
                                              {
                                                  // retrive user's details at here as shown below
                                                  NSLog(@"FB user first name:%@",user.first_name);
                                                  NSLog(@"FB user last name:%@",user.last_name);
                                                  NSLog(@"FB user birthday:%@",user.birthday);
                                                  NSLog(@"FB user location:%@",user.location);                                                      NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
                                                  NSLog(@"email id:%@",[user objectForKey:@"email"]);
                                                  NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
                                                                         user.location[@"name"]]);

                                              }
                                          }];
                                          break;

                                      case FBSessionStateClosed:
                                      case FBSessionStateClosedLoginFailed:
                                          [FBSession.activeSession closeAndClearTokenInformation];
                                          break;

                                      default:
                                          break;
                                  }

                              } ];

need ref : use this link

the console output is : enter image description here

i attached the sample project and check that - (IBAction)loginwithCustomButaction:(id)sender the project link

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

you need to ask for "user_birthday" along with public_profile .

Read more here at facebook docs

Public profile request covers

  • id
  • name
  • first_name
  • last_name
  • link
  • gender
  • locale
  • age_range

Note that you will have to get your app reviewed if you ask for any extra permission other than default public profile.

Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64