Introduction
A way to recieve a facebook user registration and split it down to parse it into a C# object.
Using the code
In your HTML page:
More info: http://developers.facebook.com/docs/plugins/registration/
<iframe src="https://www.facebook.com/plugins/registration?
client_id=[YOUR API]&
redirect_uri=[YOUR WEBSITE]/GetRegistration&
fields=name,birthday,gender,location,email,password"
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="390"
height="600">
</iframe>
In your Controller:
public JsonResult GetRegistration()
{
IDictionary<string,object> dict = DecodePayload(Request["signed_request"].Split('.')[1]);
JavaScriptSerializer serializer = new JavaScriptSerializer();
object reg = (object)dict["registration"];
string registrationJson = serializer.Serialize(reg);
IDictionary<string, object> newRegister = (IDictionary<string, object>)serializer.DeserializeObject(registrationJson);
object loc = (object)newRegister["location"];
string locationJson = serializer.Serialize(loc);
IDictionary<string, object> newLocation = (IDictionary<string, object>)serializer.DeserializeObject(locationJson);
string UserID = (string)dict["user_id"];
string namn = newRegister["name"].ToString().Replace("\"", "");
string birthday = newRegister["birthday"].ToString().Replace("\"", "");
string gender = newRegister["gender"].ToString().Replace("\"", "");
string location = newLocation["name"].ToString().Replace("\"", "");
string email = newRegister["email"].ToString().Replace("\"", "");
string password = newRegister["password"].ToString().Replace("\"", "");
string ImageURL = "graph.facebook.com/" + UserID + "/picture&type=large";
return Json("something", JsonRequestBehavior.AllowGet);
}
I got the decoding method from : Pavel Chuchuva @ http://stackoverflow.com/questions/3433252/how-to-decode-oauth-2-0-for-canvas-signed-request-in-c
public IDictionary<string, object> DecodePayload(string payload)
{
string base64 = payload.PadRight(payload.Length + (4 - payload.Length % 4) % 4, '=')
.Replace('-', '+').Replace('_', '/');
string json = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
return (IDictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);
}
Good luck!