imcc imcc - 1 year ago 174
Objective-C Question

[Facebook-iOS-SDK 4.0]How to get user email address from FBSDKProfile

I'm upgrading my app to Facebook-iOS-SDK-4.0, but seems like I can't get user email from

, since it only provide, username, userid, etc.

Answer Source

To fetch email you need to utilize the graph API, specifically providing the parameters field populated with the fields you want. Take a look at Facebook's Graph API explore tool, which can help to figure out the queries.

The code that worked for me to fetch email is the following, which assumes you are already logged in:

    NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
    [parameters setValue:@"id,name,email" forKey:@"fields"];

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                  id result, NSError *error) {
         aHandler(result, error);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download