I am using facebook sdk and facebook connect for integrating fb into my site using asp.net and c#. The user can login using the code successfully. The problem that I face is that whenever a user is logged in thru fb; if the user logs out from the facebook’s site and then tries to login through my site using fb connect, it gives error: The session is invalid because the user logged out.
I should again provide the facebook connect button to log in as it does initially but it gives error. The code used is shown below:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (ConnectAuthentication.isConnected())
{
Facebook.Session.ConnectSession _connectSession = new Facebook.Session.ConnectSession(ConfigurationManager.AppSettings["ApiKey"], ConfigurationManager.AppSettings["AppSecret"]);
if (!_connectSession.IsConnected())
{
lblStatus.Text = "Please sign-in with Facebook.";
}
else
{
Facebook.Rest.Api api = new Facebook.Rest.Api(_connectSession);
Facebook.Schema.user user = api.Users.GetInfo();
string fullName = user.first_name + " " + user.last_name;
lblStatus.Text = fullName;
}
}
else
{
lblStatus.Text = "Please sign-in with Facebook.";
}
}
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
When a user logs out the session is invalidated. You need to have the user log in again. If you don’t want to do that then please request the “offline_access” extended permission during authentication. This way the user does not have to be logged-in.
FYI, you will have to move to OAuth before September 1st 2011. Facebook will ONLY support OAuth after that.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0