Yas Tabasam
Yas Tabasam

Reputation: 10625

Facebook Graph API stopped sending user email

For some reason, Facebook stopped returning user email in the user JSON I get back after successfully authenticating a user.

I even upgraded FacebookSDK for iOS from v3.6 to v3.8 without having any luck. It was all working fine until few weeks ago but not anymore. Its just the email, all other properties i.e. DOB are coming back just fine. Facebook keeps on changing their permissions system but I'm not aware of a recent change that could have caused this. Any pointers would be greatly appreciated.

Btw, I'm trying to authenticate with my own FB account that has a valid email associated with it and I did not recently change any privacy settings either.

Have also tried deleting the app from my Facebook privacy settings and re-authorized but still no luck. Here is the code:

[FBSession openActiveSessionWithReadPermissions:@[@"user_about_me", @"user_location", @"user_birthday", @"email"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
    switch (status) {
        case FBSessionStateOpen: {
            [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                NSLog(@"User Data: %@", user);      //no email in the json
                NSString *email = user[@"email"];   //obviously returns nil
                //rest of the code
            }];
        }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }
}];

Screenshot of Facebook App permissions page that clearly shows that I have configured it correctly:

enter image description here

Here is the user JSON I get back in the API callback (I've removed my personal info).

{
    bio = "My Bio";
    birthday = "01/01/1900";
    "first_name" = FN;
    gender = male;
    id = 00000000;
    "last_name" = LN;
    link = "https://www.facebook.com/FBName";
    locale = "en";
    location =     {
        id = 11111111111111111;
        name = "City Name";
    };
    name = "FN LN";
    quotes = "";
    timezone = "0";
    "updated_time" = "2000-00-07T00:00:21+0000";
    username = USERNAME;
    verified = 1;
}

Upvotes: 4

Views: 1905

Answers (1)

Yas Tabasam
Yas Tabasam

Reputation: 10625

It turned out that Facebook does not return user email when you make a graph call if primary email associated with that Facebook account has been deactivated, disabled, or deleted.

It can happen if you do not access your email address for a long time. Facebook probably figures it out when their emails to your primary address start bouncing back.

Steps to make it work again:

  1. Please make sure you are able to login to your email account and Facebook emails are not getting bounced.

  2. Login to Facebook and change your primary email address to some other email.

  3. Facebook will send a verification email to your new email address, open this email and click verify link.

  4. Log back in to Facebook and change your primary email again to the previous email address.

  5. Facebook will send a verification email to this email address, please open it and click on it to verify your email.

  6. Wait for a couple of hours and try again viola, your email will start coming down in the json.

Upvotes: 5

Related Questions