Raja A

Raja A

  • NA
  • 438
  • 39.2k

Need to fetch User Email from Facebook api

Jan 22 2016 1:29 AM
Hi,
I have used the following code for getting facebook user's profile information for from api, But I cannot get email.. I am getting empty value, Can anyone tell me how to fix this,, Need urgent, Please help me...
I am getting this code from ....
http://www.aspsnippets.com/Articles/ASPNet-Get-FaceBook-User-details-like-Gender-Email-Address-Location-and-Birth-Date.aspx  
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPSnippets.FaceBookAPI;
using System.Web.Script.Serialization;
public partial class CSfacebook : System.Web.UI.Page
{
protected void Login(object sender, EventArgs e)
{
FaceBookConnect.Authorize("user_photos,email,user_location,user_birthday", Request.Url.AbsoluteUri.Split('?')[0]);
}
protected void Page_Load(object sender, EventArgs e)
{
FaceBookConnect.API_Key = "849760551813431";
FaceBookConnect.API_Secret = "5b8036220c5c4175865c6fb74c434425";
if (!IsPostBack)
{
if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
return;
}
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
string data = FaceBookConnect.Fetch(code, "me");
FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
pnlFaceBookUser.Visible = true;
lblId.Text = faceBookUser.Id;
lblUserName.Text = faceBookUser.UserName;
lblName.Text = faceBookUser.Name;
lblEmail.Text = faceBookUser.Email;
ProfileImage.ImageUrl = faceBookUser.PictureUrl;
lblBirthday.Text = faceBookUser.Birthday;
lblGender.Text = faceBookUser.Gender;
//lblLocation.Text = faceBookUser.Location.Name;
btnLogin.Enabled = false;
}
}
}
}
public class FaceBookUser
{
public string Id { get; set; }
public string Name { get; set; }
public string UserName { get; set; }
public string PictureUrl { get; set; }
public string Email { get; set; }
public string Birthday { get; set; }
public string Gender { get; set; }
public FaceBookEntity Location { get; set; }
}
public class FaceBookEntity
{
public string Id { get; set; }
public string Name { get; set; }
}

Answers (1)