Now, Time for Facebook Integration in .Net MVC 3.0.
Step 1 : Download Library package reference of Facebook from NuGet Package Installer.
Step 2 : import namespace of facebook as like,
using facebook;
Step 3 : This uri method handles Our call back method that will returns from facebook site after Completed Login screen.
private System.Uri RedirectUri
{
get
{
var uribuilder = new UriBuilder(Request.Url);
uribuilder.Query = null;
uribuilder.Fragment = null;
uribuilder.Path = Url.Action(“FacebookCallBack”);
return uribuilder.Uri;
}
}public ActionResult Facebook()
{
var fb = new FacebookClient();
var loginurl = fb.GetLoginUrl(new
{
client_id = “463931757029793”,
client_secret = “add31b78281d6ffccc7d1b887f77d9d4″,
redirect_uri = RedirectUri.AbsoluteUri,
responce_type = “code”,
scope = “email,publish_stream,user_hometown,user_website”
});
return Redirect(loginurl.AbsoluteUri);
}
Step 4 : Now, get the Details from facebook Client..
public ActionResult FacebookCallBack(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post(“oauth/access_token”, new
{
client_id = “463931757029793”,
client_secret = “add31b78281d6ffccc7d1b887f77d9d4″,
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});var accessTocken = result[0];
Session[“AccessTocken”] = accessTocken;
fb.AccessToken = accessTocken;dynamic me = fb.Get(“me?fields=first_name,last_name,id,email”);String email = me[3];return RedirectToAction(“LoginView”);
}
Now, Finally this is Done…!!!
Yippee. Always Enjoy coding !!
0 comments:
Post a Comment