开发者

Facebook connect fbs_[app_id] cookie not being set from JavaScript SDK

I'm using the Graph API via JavaScript SDK like this (this is basic example straight from documentation):

<html> 
<head> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> 

<script type="text/javascript"> 

$(document).ready(function() {
  $('#login').click(function() {

    FB.login(function(response) {
      if (response.authResponse) {
        console.log('Welcome!  Fetching your information.... ');
        FB.api('/me', function(response) {
          console.log('Good to see you, ' + response.name + '.');
        });
      } else {
        console.log('User cancelled login or did not fully authorize.');
      }
    });

  })
})

</script> 

</head> 

<body> 

  Hellow!
  <a href="#" id="login">Login</a> 

  <div id="fb-root"></div> 
  <script src="http://connect.facebook.net/en_US/all.js"></script> 
    <script> 
      window.fbAsyncInit = function() {
        FB.init({
          appId: '249274258430595',
          cookie: true,
          status: true,
          xfbml: true,
          oauth: true
        });
      };
    </script> 

</body> 

</html> 

It's also possible to test it live here:

http://bitcells.com

This cookie I need for backend access to API (fbs_249274258430595) is not being set.

Only something called fbsr_249274258430595 is present and this is not what I need. I tested this with FireCookie extension for Firebug.

I really don't understand how this basic example is not working right - meaning that I want to use 开发者_如何学编程API from the backend code (PHP, Ruby etc.).

Any ideas?

Thank you!

David


I, on the other hand ended up setting my own cookie which server side can read:

I have one checkbox which asks user if he wants to share on fb, here is the code:

  function setFbCookies(response) {
    Cookie.set('fb_access_token', response.authResponse.accessToken, {path: '/'})
    Cookie.set('fb_user_id', response.authResponse.userID, {path: '/'})
  }

  when('#share_on_fb', function(checkbox) {
    checkbox.observe('change', function(ev) {
      if(checkbox.getValue()) {
        FB.getLoginStatus(function(response) {
          if (response.authResponse) {
            setFbCookies(response)
          } else {
            FB.login(function(response) {
              if (response.authResponse) {
                setFbCookies(response)
              } else {
                checkbox.checked = false
              }
            }, {scope: 'publish_stream'});
          }
        })
      }
    })
  })

And here is the reason why fbs_xxxxx cookie doesn't get set: https://developers.facebook.com/blog/post/525/

It looks like if you use oath=false, then it does get set, but this is only valid until 1st of october. There is still no documentation on how to get encrypted access token from the new fbsr_xxxxxx cookie.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜