Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[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 FBSDKProfile, since it only provide, username, userid, etc.

like image 223
imcc Avatar asked Mar 28 '15 22:03

imcc


People also ask

What is the latest version of Facebook SDK for iOS?

The current version of the Facebook SDK for iOS is version 14.1. 0.

What is Facebook SDK for iOS?

The Facebook SDK enables: Facebook Login - Authenticate people with their Facebook credentials. Share and Send dialogs - Enable sharing content from your app to Facebook. App Events - Log events in your application.

What does Facebook SDK stand for?

The Facebook SDK for Android gives you access to the following features: Facebook Login — A secure and convenient way for people to log into your app or website by using their Facebook credentials. Sharing — Enable people to post to Facebook from your app. People can share, send a message, and share to stories.


1 Answers

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. https://developers.facebook.com/tools/explorer

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);      }]; 
like image 192
genericdan Avatar answered Oct 05 '22 18:10

genericdan