Facebook Sdk 3.0: How to Receive User's E-Mail

Facebook SDK 3.0: how to receive user's e-mail?

if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
self.nameLabel.text = user.name;
self.emailLabel.text = [user objectForKey:@"email"];
}
}];
}

Because FBGraphUser doesn't have an email @property, we can't access the information like with the name (dot-syntax), however the NSDictionary still has the email kv-pair and we can access it like we would do with a normal NSDictionary.

Don't forget to ask for the email permission though:

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self facebookSessionStateChanged:session state:state error:error];
}];

Get a users email with Facebook SDK

There is only one correct place for the scope parameter:

<div
class="fb-login-button" data-max-rows="1" data-size="large"
data-button-type="continue_with" data-show-faces="false"
data-auto-logout-link="false" data-use-continue-as="false"
data-scope="email"
>
</div>

Facebook Graph API, how to get users email?

The only way to get the users e-mail address is to request extended permissions on the email field. The user must allow you to see this and you cannot get the e-mail addresses of the user's friends.

http://developers.facebook.com/docs/authentication/permissions

You can do this if you are using Facebook connect by passing scope=email in the get string of your call to the Auth Dialog.

I'd recommend using an SDK instead of file_get_contents as it makes it far easier to perform the Oauth authentication.

How to get a user's email from an access token using the Facebook Python SDK

Make sure that

a) the user has actually granted the permission to your app (request /me/permissions to confirm, using the same access token), and

b) that their e-mail address is verified with Facebook. (Apparently not automatically the case with the e-mail address used to register.)

Getting user e-mail with facebook C# sdk

André,

Your login-buttons is already requesting the permission to access the email address.

Why don't you use the FacebookClient? If you're running .NET 4.0, it's so simple as this:

var client = new FacebookClient();
dynamic me = client.Get("me");
string firstName = me.first_name;
string lastName = me.last_name;
string email = me.email;

Check this documentation: http://facebooksdk.codeplex.com/wikipage?title=Code%20Examples&referringTitle=Documentation

How to get user name and email id for Facebook SDK?

Use the Following Code

 FBSession *session = [[FBSession alloc] initWithPermissions:@[@"basic_info", @"email"]];
[FBSession setActiveSession:session];

[session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
NSLog(@"accesstoken %@",[NSString stringWithFormat:@"%@",session.accessTokenData]);
NSLog(@"user id %@",user.id);
NSLog(@"Email %@",[user objectForKey:@"email"]);
NSLog(@"User Name %@",user.username);
}
}];
}
}];

How to get user email and birthday from Facebook API Version v2.4

You'll have to explicitly define which fields you want to retrieve with your request, for example /me?fields=id,name,email,birthday instead of just /me

See

  • https://developers.facebook.com/docs/apps/changelog#v2_4

To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

iOS Facebook get user's e-mail

I have not code for graph API,

but with new facebook sdk version 3, I have code for that.

-(void)openFbSession
{
[[self appDelegate].session closeAndClearTokenInformation];

NSArray *permissions = [NSArray arrayWithObjects:@"email",@"user_location",@"user_birthday",@"user_hometown",nil];
[self appDelegate].session = [[FBSession alloc] initWithPermissions:permissions];

[[self appDelegate].session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if(!error)
{
NSLog(@"success");
[self myFbInfo];
}
else
{
NSLog(@"failure");
}

}];
}

and for all information, myFbInfo method is

-(void)myFbInfo
{
[FBSession setActiveSession:[self appDelegate].session];

[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
if (error) {
// Handle error
}

else {
//NSString *userName = [FBuser name];
//NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser id]];
NSLog(@"Name : %@",[FBuser name]);
NSLog(@"first name : %@",[FBuser first_name]);
NSLog(@"Last name : %@",[FBuser last_name]);
NSLog(@"ID : %@",[FBuser id]);
NSLog(@"username : %@",[FBuser username]);
NSLog(@"Email : %@",[FBuser objectForKey:@"email"]);

NSLog(@"user all info : %@",FBuser);

}
}];

}

EDIT


in appdelegate.h

@property (strong, nonatomic) FBSession *session;

in appdelegate.m

- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{
//NSLog(@"FB or Linkedin clicked");
return [self.session handleOpenURL:url];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
[FBSession.activeSession handleDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
[self.session close];
}


Related Topics



Leave a reply



Submit