0

Hi im using an unoffical fb Coldfusion SDK i had to convert it all from using CFscript to conventional cffunctions because im still on CF7. Everything seems to be working but im not sure why when trying to lookup the cookie on login at server side its not found. Its seems to be fine on Chorme but FF, IE and Opera all have the same issue.

On index.cfm i have a fb:login button, when pressed you get the log in screen, once successfully logged in, index.cfm refreshs runs my FacebookApp methods but returns a blank value for access_token when read from server side. This is because at server side i try to get the info from the cookie but the cookie has not been created. Ive also outputted the value of access_token but it returns as blank. When i press F5 about a second later I now see the value for my access_token in my output. At the same time if I use the js alert to display access_token in getLoginStatus i can see the value.

Ive read in some places for older browsers where the SDK is slow to load to use the channelURL param, which ive done but im still getting the same result as above.

Any suggestions what I can do? I tried adding js timeout to slow down the to getLoginStatus so it had time to read the cookie but ive not had any joy. Please help.

Top of the page i have this

<!doctype html PUBLIC "-//W3C//Dtd html 4.0 Transitional//EN">
<html xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">

After the body tag i have the following

    <div id="fb-root"></div>

            <script>
              window.fbAsyncInit = function() {
                 FB.init({
                  appId  : 'xxxxxxxxxxxxxxxx',
                  cookie  : true, // enable cookies to allow the server to access the session
                  oauth   : true, // OAuth 2.0
                  status  : true, // check login status
                  xfbml   : true, // parse XFBML
                  channelUrl: document.location.protocol + './/www.sitename.com/fbchannel.html' //custom channel
                });

                // whenever the user logs in or logs out, we refresh the page
                FB.Event.subscribe('auth.login', function(response) {
                   window.location.reload();
                   alert('login');
                });

                FB.Event.subscribe('auth.logout', function(response) {
                   window.location.reload();
                   //alert('logout');
                });

                FB.getLoginStatus(function(response) {
                  if (response.status == 'connected') {
                    // the user is logged in and connected to your
                    // app, and response.authResponse supplies
                    // the user's ID, a valid access token, a signed
                    // request, and the time the access token 
                    // and signed request each expire
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;

                    //alert('end');
                   // alert('login url called '+unescape(window.location.pathname));
                    // whenever the user logs in we refresh the page

                    //alert(accessToken);

                  } else if (response.status == 'not_authorized') {
                    // the user is logged in to Facebook, 
                    //but not connected to the app
                  } else {
                    // the user isn't even logged in to Facebook.
                  }
                 });

              };

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

Somewhere way below the stuff above i have my button

<fb:login-button scope="publish_stream,email" autologoutlink="true">Connect with FB</fb:login-button>
david-l
  • 623
  • 1
  • 9
  • 20

1 Answers1

0

After spending DAYS on this trying to figure out the problem i came across this and its made my day, problem solved! Thanks chwk.

Community
  • 1
  • 1
david-l
  • 623
  • 1
  • 9
  • 20