public class ConnectAuthentication { public ConnectAuthentication() { } public static bool isConnected() { return (SessionKey != null && UserID != -1); } public static string ApiKey { get { return ConfigurationManager.AppSettings["APIKey"]; } } public static string SecretKey { get { return ConfigurationManager.AppSettings["Secret"]; } } public static string SessionKey { get { return GetFacebookCookie("session_key"); } } public static long UserID { get { long userID = -1; long.TryParse(GetFacebookCookie("user"), out userID); return userID; } } private static string GetFacebookCookie(string cookieName) { string retString = null; string fullCookie = ApiKey + "_" + cookieName; if (HttpContext.Current.Request.Cookies[fullCookie] != null) retString = HttpContext.Current.Request.Cookies[fullCookie].Value; return retString; } } Here is how the ConnectAuthentication Class is used in my page load : if (ConnectAuthentication.isConnected()) { Facebook.Session.ConnectSession session = new Facebook.Session.ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey); _connectSession = new ConnectSession(ConnectAuthentication.ApiKey, ConnectAuthentication.SecretKey); Api _facebookAPI = new Api(_connectSession); _connectSession.UserId = ConnectAuthentication.UserID; Facebook.Rest.Api api = new Facebook.Rest.Api(_connectSession); //Display user data captured from the Facebook API. Facebook.Schema.user user = api.Users.GetInfo(); string fullName = user.first_name + " " + user.last_name; Panel1.Visible = true; Label1.Text = fullName; } else { //Facebook Connect not authenticated, proceed as usual. } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)