2011-09-25 46 views
0

我使用FB.ui与应用Facebook标签授权使用简单:的OAuth 2.0饼干不是页面选项卡上设置有FB.ui

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的标准流。

回答

0

我有完全相同的问题。除了使用FB.login(它弹出一个新窗口)以外,似乎无法在不刷新页面的情况下获取访问令牌。

你可能想要做的是使一个AJAX调用另一个页面FB.ui响应后返回的访问令牌:

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; 

?>