使用ASP.NET从Facebook获取名字,姓氏和电子邮件地址

我的Startup.Auth.cs文件中有以下代码,但我找不到从Facebook获取名字和姓氏的方法:

var facebookOptions = new FacebookAuthenticationOptions() { AppId = "", AppSecret = "", BackchannelHttpHandler = new FacebookBackChannelHandler(), UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,email" }; facebookOptions.Scope.Add("email"); facebookOptions.Scope.Add("public_profile"); app.UseFacebookAuthentication(facebookOptions); 

这是一个快速示例,说明如何从asp.net winforms中获取Facebook的用户信息。 此示例使用Facebook SDK for .Net 。 此代码段使用Facebook登录用户,然后获取额外的用户信息,但也可用于获取额外的个人资料数据。

 static string Facebook_Key = "yourAppID"; static string Facebook_Secret = "yourAppSecret"; protected void Page_Load(object sender, EventArgs e) { //check if the user is returning from Facebook if (Request.QueryString["code"] != null) { FacebookClient fbc = new FacebookClient(); //retreive the access token dynamic result = fbc.Post("oauth/access_token", new { client_id = Facebook_Key, client_secret = Facebook_Secret, redirect_uri = Request.Url.AbsoluteUri, code = Request.QueryString["code"].ToString() }); fbc.AccessToken = result.access_token; //get the extra profile data dynamic user = fbc.Get("me?fields=first_name,last_name,id,email"); //display the results FacebookLoginLabel.Text += user.id + "
"; FacebookLoginLabel.Text += user.first_name + "
"; FacebookLoginLabel.Text += user.last_name + "
"; FacebookLoginLabel.Text += user.email + "
"; //start the actual aspnet registration or login LoginOrRegisterUser(); } } protected void FacebookLoginButton_Click(object sender, EventArgs e) { FacebookClient fbc = new FacebookClient(); //start the Facebook login request var loginUrl = fbc.GetLoginUrl(new { client_id = Facebook_Key, redirect_uri = Request.Url.AbsoluteUri, response_type = "code", scope = "email" }); //redirect the user to Facebook for authentication Response.Redirect(loginUrl.AbsoluteUri); }

ASPX