DotNetOpenAuth获取Facebook电子邮件地址

时间:2011-03-18 18:39:27

标签: facebook dotnetopenauth

我有以下代码,其中抓取了First / Last名称。我意识到电子邮件是一个扩展权限,但我需要修改什么才能请求扩展权限?

如何通过DotNetOpenAuth

获取经过身份验证的Facebook用户的电子邮件
        fbClient = new FacebookClient
        {
            ClientIdentifier = ConfigurationManager.AppSettings["facebookAppID"],
            ClientSecret = ConfigurationManager.AppSettings["facebookAppSecret"],
        };

        IAuthorizationState authorization = fbClient.ProcessUserAuthorization();
        if (authorization == null)
        {
            // Kick off authorization request
            fbClient.RequestUserAuthorization();

        }
        else
        {
            var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    var graph = FacebookGraph.Deserialize(responseStream);

                    // unique id for facebook based on their ID
                    FormsAuthentication.SetAuthCookie("fb-" + graph.Id, true);

                    return RedirectToAction("Index", "Admin");
                }
            }
        }

        return View("LogOn");

2 个答案:

答案 0 :(得分:11)

添加以下位:

            var scope = new List<string>();
            scope.Add("email");
            fbClient.RequestUserAuthorization(scope);

答案 1 :(得分:1)

如果您使用内置oauth提供程序的VS2012,则只需更新oauth包。请参阅以下链接上的最后一篇文章:http://forums.asp.net/t/1847724.aspx/1。我无法检索的唯一电子邮件是MS Live。目前我使用facebook,google和yahoo。