How can i know user is already logged in onto Facebook?
I am using Facebook Connect in my application. Everything works out pretty well. Howe开发者_如何学Cver on my page in constructor, i want to know user already has logged into Facebook i want to display a different page rather than login page. How can i do this? I am using Facebook Developer Toolkit 3.1 and Silverlight 4.0. In short, i want to know whether the user is connected to facebook or not.
Thanks in advance :)
Note - this is in MVC - if you are using Silverlight, you may need to modify some of the code.
I've used the following. In my "landing page" I have the following:
if (Request.Cookies["AuthenticatedViaFacebook"] != null)
{
string val = Server.HtmlEncode(Request.Cookies["AuthenticatedViaFacebook"].Value);
if (val == "true")
{
return RedirectToAction("Login", "Account");
}
}
In the Account/Login page I do a quick re-direct to facebook:
var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
oAuthClient.RedirectUri = new Uri(ConfigurationManager.AppSettings["RedirectUrl"]);
var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
return Redirect(loginUri.AbsoluteUri + "&scope=user_birthday");
If it comes back succesfull - I authorize the user and send them into the system.
I store the facebook id in my database, so I know what user it is.
I don't know of a quicker, or better way of doing it - this works pretty quickly. You see the facebook page url for a second or so and then you are in your system
精彩评论