无法从服务器端检索facebook access_token, SDK加载太慢



我使用的是一个非官方的fb Coldfusion SDK,我不得不将它从使用CFscript转换为常规功能,因为我仍然在CF7上。一切似乎都在工作,但我不知道为什么当试图查找在服务器端登录它没有找到的cookie。在chrome上似乎没问题,但FF、IE和Opera都有同样的问题。

索引。CFM我有一个fb:登录按钮,当按下你得到登录屏幕,一旦成功登录,索引。cfm刷新运行我的FacebookApp方法,但从服务器端读取access_token时返回一个空白值。这是因为在服务器端,我试图从cookie中获取信息,但cookie尚未创建。我还输出了access_token的值,但它返回为空白。大约一秒钟后,当我按下F5时,我现在可以在输出中看到access_token的值。同时,如果我使用js alert在getLoginStatus中显示access_token,我可以看到值。

我在一些地方读到旧的浏览器,其中SDK加载缓慢,使用channelURL参数,我做了,但我仍然得到与上面相同的结果。

有什么建议吗?我尝试添加js超时来减慢到getLoginStatus的速度,这样它就有时间读取cookie,但我没有任何乐趣。请帮助。

在页面顶部我有这个

<!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">

在body标签之后,我有以下

    <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>

上面的东西下面有我的按钮

<fb:login-button scope="publish_stream,email" autologoutlink="true">Connect with FB</fb:login-button>

在花了几天时间试图找出问题后,我遇到了这个,它让我的一天,问题解决了!谢谢chwk。

最新更新