1
Answer

Need to fetch Email from Facebook api

Raja A

Raja A

9y
337
1
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...
 
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)
0
Santiago Felipe
NA 2 0 9y
Do you mean you want to convert the JPEG image to PNG while loading the JPEG image (and not after)?

Are you selecting and loading the JPEG image using the OpenFileDialog Class?

If yes, you can get the name of the JPEG file, pass it Image.FromFile method:
https://msdn.microsoft.com/en-us/library/system.drawing.image.fromfile.aspx
And then save it to PNG using the
Image.Save method (Stream, ImageFormat):
https://msdn.microsoft.com/en-us/library/ms142147.aspx

But if you face any problem while loading or saving the JPEG or PNG images, you can try using loading and saving features from leadtools programming toolkit.
0
Raja T
NA 7.4k 6k 9y
Hi,

Please refer below URLs

http://stackoverflow.com/questions/17294737/converting-an-image-to-png-on-upload


http://stackoverflow.com/questions/3906260/how-can-i-convert-a-jpeg-image-to-a-png-one-with-transparent-background


http://www.c-sharpcorner.com/UploadFile/scottlysle/ImageConverter09132006105604AM/ImageConverter.aspx

Thanks