Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
 protected void Login(object sender, EventArgs e)
    {
        FaceBookConnect.Authorize("user_photos,email", Request.Url.AbsoluteUri.Split('?')[0]);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        FaceBookConnect.API_Key = "753961091398319";
        FaceBookConnect.API_Secret = "key";
        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".ToString(), 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;
                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; }
}



[^][^]i want to fetch the email of the logged in user but it showing me only the user name and id what to do, how do i get the user email
Posted
Updated 3-May-17 0:52am
v2
Comments
Member 12314184 22-Mar-17 8:05am    
Does anyone have a solution I ran into the same problem.
CHill60 3-May-17 7:51am    
For some reason two solutions have been posted today - see below

Change
string data = FaceBookConnect.Fetch(code, "me")

to
string data = FaceBookConnect.Fetch(code, "me?fields=email");


the syntax of other variables like UserName, name etc... can be consulted on

[https://developers.facebook.com/docs/facebook-login/permissions

Example:

string data = FaceBookConnect.Fetch(code, "me?fields=email,first_name,last_name");
 
Share this answer
 
v4
To get access publically you need to set your facebook application live.

I mean you need to ask for permission first then your application will be under review and after approval from facebook, you can able to get information of others too.

But before accessing an information you must have to define it in scope for permission

For more info see my question also

Facebook app permission issue.[^]

Let me know if you have any query or concern for same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900