Hi,
I am really in need of some urgent help please. I am trying to get a new users details from Facebook in C# MVC. I downloaded the NuGet package in Visual Studio and put the code below in my controller.
My questions are:
1. How would I get the code(access token) in C#? Is there a way I can generate one? All the examples I see don't mention how you get it but they just show the code as a parameter in the method.
2. For testing, I created an access token on the Facebook website to see if the user details comes through correctly. I get an error doing this, saying the invalid URL. I searched on Google and I see its because of the localhost url, does anyone know a way around this?
Thanks For all the help.
public ActionResult FacebookCallback(string EmailAddress, string Password, string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "XXXXXXXXXXX",
client_secret = "YYYYYYYYYYYYYYYYYYY",
redirect_uri = "http%3a%2f%2flocalhost%3a43568%2fRegister",
code = <big>code</big>
});
var accessToken = result.access_token;
Session["AccessToken"] = accessToken;
fb.AccessToken = accessToken;
dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
string email = me.email;
string firstname = me.first_name;
string middlename = me.middle_name;
string lastname = me.last_name;
FormsAuthentication.SetAuthCookie(email, false);
return RedirectToAction("Index", "Home");
}