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

发布于 2024-12-22 06:59:29 字数 3561 浏览 1 评论 0原文

您好,我使用非官方 fb Coldfusion SDK 我必须将其转换所有这些都从使用 CFscript 到传统的 cffunctions,因为我仍在使用 CF7。 一切似乎都正常,但我不确定为什么当尝试在服务器端登录时查找 cookie 时找不到它。在 Chorme 上似乎没问题,但 FF、IE 和 Opera 都有同样的问题。

在index.cfm上,我有一个fb:登录按钮,按下时您会看到登录屏幕,成功登录后,index.cfm刷新运行我的FacebookApp方法,但从服务器端读取时返回access_token的空白值。这是因为在服务器端我尝试从 cookie 获取信息,但 cookie 尚未创建。我还输出了 access_token 的值,但它返回为空白。大约一秒钟后,当我按 F5 时,我现在在输出中看到了 access_token 的值。同时,如果我使用js警报在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">

在正文标签之后我有以下内容

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞觅青森が 2024-12-29 06:59:29

在花了几天时间试图找出问题之后,我遇到了

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文