Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook iOS SDK not returning user email

I am trying to get access to some user's info, including email. For this purpose, I use the Graph API to call this method:

[facebook requestWithGraphPath:@"me" andDelegate:self];

It returns the user info, without the email information (the birthday is also missing). I setted all permissions and tested with more than one account (which has email and birthday as a public information), and accepted all the dialog's requests.

Here is my init:

if(!facebook) {
    facebook = [[Facebook alloc] initWithAppId:[self _APP_KEY] andDelegate:self];
    NSArray *array =  [NSArray arrayWithObjects: @"email", @"user_birthday", @"publish_stream", @"offline_access", nil];
    [self setPermissions:array];
}

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}

if (![facebook isSessionValid]) {
    [facebook authorize:permissions];
} 
else {
    [self getUserInfo];
}

The login callback:

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

    [self getUserInfo];
}

The getUserInfo method:

- (void) getUserInfo {
    [facebook requestWithGraphPath:@"me" andDelegate:self];
}

The request callback:

 - (void)request:(FBRequest *)request didLoad:(id)result {

    if ([result isKindOfClass:[NSDictionary class]]) {
        NSDictionary* json = result;
        NSLog(@"-> %@", json);
    }
}

The result is the following:

-> {
    "first_name" = EDITED (my name);
    gender = male;
    hometown =     {
        id = 111072692249998;
        name = "Porto Alegre";
    };
    id = 653099452;
    languages =     (
                {
            id = 104034306299811;
            name = "Brazilian Portuguese";
        },
                {
            id = 106059522759137;
            name = English;
        }
    );
    "last_name" = EDITED (my last name);
    link = EDITED (my profile);
    locale = "en_US";
    location =     {
        id = 112047398814697;
        name = "S\U00e3o Paulo, Brazil";
    };
    name = EDITED (my name);
    timezone = "-3";
    "updated_time" = "2012-04-25T13:36:51+0000";
    verified = 1;
}

As you can see, there is no information about the user's email. Am I missing some step? Any ideias?

Thanks in advance

like image 565
Roger Sanoli Avatar asked Apr 25 '12 14:04

Roger Sanoli


People also ask

Does Facebook SDK use IDFA?

The Facebook SDK includes code to access Apple's Advertising Identifier (IDFA), but that code is only executed in certain situations.

What is Facebook SDK for IOS?

The Facebook SDK is what allows mobile app developers to integrate Facebook within a mobile app. SDK stands for software development kit, and it allows for a website or app to integrate with Facebook seamlessly. Examples of what you can do with Facebook SDK include: Facebook Login functionality.


2 Answers

Try to use this, it works in my case

facebook = [[Facebook alloc] initWithAppId:[self _APP_KEY] andDelegate:self]; [facebook authorize:[NSArray arrayWithObjects:@"email",nil]];

like image 183
Manish Agrawal Avatar answered Sep 19 '22 04:09

Manish Agrawal


Try this permissions = [[NSArray alloc] initWithObjects:@"offline_access",@"email",nil];

like image 22
Ambili B Menon Avatar answered Sep 23 '22 04:09

Ambili B Menon