开发者

OAuth 2.0 cookie not set with FB.ui on Page tab

开发者 https://www.devze.com 2023-04-07 16:22 出处:网络
I am usin开发者_StackOverflow社区g FB.ui to authorize with application Facebook tab using simple:

I am usin开发者_StackOverflow社区g FB.ui to authorize with application Facebook tab using simple:

FB.init({
  appId  : '<%= Facebook::APP_ID %>',
  status : true, // check login status
  cookie : true, // enable cookies to allow the server to access the session
  xfbml  : true,  // parse XFBML
  channelUrl  : 'http://<%= request.host_with_port %>/channel.html', // Custom Channel URL
  oauth : true //enables OAuth 2.0
});

FB.ui({
    method: 'oauth'
  },
  function(response) {
    // do some redirect stuff here
});

Authorization goes fine, but even when user confirms the application, the relevant fbsr_xxxxx cookie is not set. Is there any way to force it? Response object contains user_id, but I would rather use the standard flow with signed_request.


I'm having the exact same issue. There seems to be no way to get the access token without refreshing the page other than using FB.login, which pops out a new window.

What you may want to do is make an ajax call to another page to return the access token after the FB.ui response:

FB.ui({
    method: 'oauth'
  },
  function(response) {
   if(response.session){
$.get('return_token.php', function(response){
var access_token = response;
alert(access_token);
})
}
});




return_token.php:

<?
  $config = array(
    'appId' => $app_id,
    'secret' => $secret
  );

  $facebook = new Facebook($config);

  try {$access_token = $facebook->getAccessToken();}catch(FacebookApiException $e) {

        $result = $e->getResult();
        echo json_encode($result);

  }

echo $access_token;

?>
0

精彩评论

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