0

我正在使用 FB.ui 使用简单的应用程序 Facebook 选项卡进行授权:

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
});

授权很好,但即使用户确认应用程序,相关的 fbsr_xxxxx cookie 也没有设置。有什么办法可以强制吗?响应对象包含 user_id,但我宁愿将标准流程与 signed_request 一起使用。

4

1 回答 1

0

我有完全相同的问题。除了使用弹出一个新窗口的 F​​B.login 之外,似乎没有办法在不刷新页面的情况下获取访问令牌。

您可能想要做的是在 FB.ui 响应之后对另一个页面进行 ajax 调用以返回访问令牌:

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;

?>
于 2011-10-01T06:37:39.737 回答