Alexa Adrian
Alexa Adrian

Reputation: 1858

Using Facebook to publish on facebook application page

I implemented 6 months ago in our web application site(Asp.Net) a page where you could authenticate Facebook to use your Facebook account to publish a message current fb user logged wall. Now, it seams that this is not working any longer. I don't know why. I suspect that Facebook has changed again their api. I can give you some code I have or please tell me the ultimate solution for what I try to implement. So: I have this

then at the bottom:

<!-- inserted for fb temp -->
    <div id="fb-root">
    </div>
    <script type='text/javascript'>
        window.fbAsyncInit = function () {
            FB.init({ appId: '<%= FacebookAppID %>', status: true, cookie: true, xfbml: true });
            /* sample events to respond to*/
            FB.Event.subscribe('auth.login', function (response) { });
            FB.Event.subscribe('auth.logout', function (response) { });
            FB.getLoginStatus(function (response) { });

        };
        (function () {
            //alert(document.location.protocol);
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        } ());

    </script>

I suspect that there is a problem with getting cookie, however. In FacebookConnect.cs is this function

private string GetFacebookCookieValue(string cookieValue)
        {
            string tmp = "";
            string cookieName = "fbs_" + ConfigurationManager.AppSettings["AppID"];
            tmp += cookieName + "";
            string retString = null;
            HttpCookie c = HttpContext.Current.Request.Cookies[cookieName];

            if (HttpContext.Current.Request.Cookies[cookieName] != null)
            {
                retString = HttpContext.Current.Request.Cookies[cookieName][cookieValue];
                tmp += " [[" + HttpContext.Current.Request.Cookies[cookieName][cookieValue];
            }
            else
            {
                //tmp += c.ToString() + "]] ";
            }

            //throw new Exception(tmp);
            return retString;
        }

when I look for cookies set for my website I don't find any cookie with name fbs_ , onlt fbsr_

Update:

 public string AccessToken
        {
            get
            {
                //NOTE: oddly enough the accesstoken key in the cookie is actually \"access_token
                string token = GetFacebookCookieValue("\"access_token");
                return token;
            }
        }

Upvotes: 1

Views: 614

Answers (1)

shrutyzet
shrutyzet

Reputation: 529

Yes, you should read the fbsr cookie. Also, its value has been changed. The cookie will not contain the access token anymore. Instead you will get a code, with which you will have to submit to a request to Facebook for the access token to this url, replacing with appropriate values:

https://graph.facebook.com/
  oauth/access_token?client_id={0}&redirect_uri=&client_secret={1}&code={2}

Upvotes: 2

Related Questions