OAuth with Facebook
1. 链接到这登录
https://graph.Facebook.com/oauth/authorize?type=user_agent&client_id= CLIENT_ID&redirect_uri=REDIRECT_URL&scope=user_photos,email,user_birthday, user_online_presence
2. 回调地址里获取access_token并保存。
http://REDIRECT_URL?access_token=142279789131336%7C2.WKMyHmlbzscco7HjrkJUMw__.3600.1304560800.1-100000131478113%7Clt6C8GVbq0sf_GwTOrzO7dXsCrA&expires_in=03. 获取我的资料https://graph.facebook.com/me?access_token=142279789131336|cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx90|lt6C8GVbq0sf_GwTOrzO7dXsCrAWebClient client = new WebClient(); string JsonResult = client.DownloadString(string.Concat("https://graph.facebook.com/me?access_token=", token)); // Json.Net is really helpful if you have to deal with Json from .Net http://json.codeplex.com/ JObject jsonUserInfo = JObject.Parse(JsonResult); // you can get more user's info here. Please refer to: http://developers.facebook.com/docs/reference/api/user/ string username = jsonUserInfo.Value<string>("username"); string email = jsonUserInfo.Value<string>("email"); string locale = jsonUserInfo.Value<string>("locale"); int facebook_userID = jsonUserInfo.Value<int>("id"); // store user's information here... FormsAuthentication.SetAuthCookie(username, true); return RedirectToAction("Index", "Home");FacebookClient:FacebookClient client = new FacebookClient("AccessToken");); dynamic result = client.Get("me"); ViewBag.Firstname = (string)result.first_name; ViewBag.Lastname = (string)result.last_name + "--->" + (string)result.email;