Login using Facebook Problem after logging out

折月煮酒 提交于 2019-12-20 07:05:04

问题


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.";
            }
        }
}

回答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.



来源:https://stackoverflow.com/questions/6178945/login-using-facebook-problem-after-logging-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!