Question

I am using 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.

Was it helpful?

Solution

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;

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top