如何在登录过程中获取facebook的电子邮件

时间:2015-10-01 12:30:28

标签: asp.net facebook-graph-api

 FaceBookConnect.API_Key = <>;
 FaceBookConnect.API_Secret = <>;
        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);
            lblId.Text = faceBookUser.Id;
            lblUserName.Text = faceBookUser.UserName;
            lblName.Text = faceBookUser.Name;
            lblEmail.Text = faceBookUser.Email;
            ProfileImage.ImageUrl = faceBookUser.PictureUrl;

1 个答案:

答案 0 :(得分:0)

  
    

Graph API是将数据输入和输出Facebook社交图的主要方式。它是一个基于HTTP的低级API,可用于查询数据,发布新故事,上传照片以及应用可能需要执行的各种其他任务

  

所以你在这里使用Graph API,但为此你需要你想要读取数据的用户的许可。如需许可

FaceBookConnect.Authorize("about,email", Request.Url.AbsoluteUri);

有用的链接:

  1. http://www.aspsnippets.com/Articles/ASPNet-Get-FaceBook-User-details-like-Gender-Email-Address-Location-and-Birth-Date.aspx
  2. https://developers.facebook.com/tools/explorer/145634995501895/