2011-09-25 22 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; 

?>