Good evening!
I’m developing a web application with asp.net C#. In this application the user has the option to create a login using its facebook account (facebook connect).
I’m using thye facebook C# sdk from codeplex (http://facebooksdk.codeplex.com/).
I can easily retrieve the name, photo , etc…. but I don’t know how to retrieve the user e-mail.
To call the FB login button I use this code:
<fb:login-button onlogin="window.location.reload()" perms='email'></fb:login-button>
It works just fine and to retrieve user’s info I use this C# code:
// Authenticated, created session and API object
sessaoFB = new ConnectSession(APPLICATION_KEY, SECRET_KEY);
if (!sessaoFB.IsConnected()) {
this.phLogar.Visible = true;
this.phLogado.Visible = false;
} else {
// Authenticated, create API instance
_facebookAPI = new Api(sessaoFB);
Auth auth = new Auth(sessaoFB);
if (!this.Page.IsPostBack)
{
this.phLogar.Visible = false;
this.phLogado.Visible = true;
try
{
//User data
user usuarioFB = _facebookAPI.Users.GetInfo();
this.lblNome.Text = usuarioFB.first_name;
imgFoto.ImageUrl = usuarioFB.pic_big;
}
catch (Exception ex)
{
this.lblNome.Text = ex.Message;
}
}
}
How can I get the user’s e-mail suing the facebook C# sdk? Do any of you guys know?
Thanks in advance for any help!
Best regards.
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:
Check this documentation: http://facebooksdk.codeplex.com/wikipage?title=Code%20Examples&referringTitle=Documentation