2015-03-19 46 views
0

我想在facebook標籤下整合我的網站(並非全部只是一個特定的部分)並檢索用戶信息,我成功完成了它。但問題是,當我瀏覽網站頁面時,我無法獲取用戶信息。Facebook的自定義標籤:我無法獲得FacebookSession的子頁

例如,如果我使用: mysite.org/foo作爲主頁,在這裏我可以得到所需的用戶信息沒有任何問題。 但是當我導航到mysite.org/foo/bar然後會話返回null。

\Facebook\FacebookSession::setDefaultApplication(APP_KEY, APP_SECRET); 
    $helper = new \Facebook\FacebookCanvasLoginHelper(); 

    try { 
     $session = $helper->getSession(); 
    } catch (\Facebook\FacebookRequestException $e) { 
     echo "Exception occured, code: ".$e->getCode(); 
     echo " with message: ".$e->getMessage(); 
    } catch (Exception $e) { 
     echo "Exception occured, code: ".$e->getCode(); 
     echo " with message: ".$e->getMessage(); 
    } 

我使用JavaScript SDK的提前登錄

window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : APP_KEY, 
     xfbml  : true, 
     version : 'v2.1' 
    }); 
    FB.getLoginStatus(function(response) { 
     if (response.status === 'connected') { 
      console.log('Logged in.'); 
     } 
     else { 
      console.log('Logging.'); 
      FB.login(function(response) {},{scope: 'email'}); 
     } 
    }); 
    }; 

感謝。

回答

0

問題解決了:)

我有後請求更換站點中的所有鏈接和內發送「signed_request」。

這裏可能需要一些改進解決方案

<script type="text/javascript"> 
$(document).ready(function(){ 
    var $form = $('<form name="temp" method="POST"/>'); 
    $form.append('<input type="hidden" name="signed_request" value="<?=$_REQUEST['signed_request']; ?>" />'); 
    $form.appendTo($('body')); 

    $('a').click(function(e){ 
     var href = $(this).attr('href'); 
     if(!isExternal(href)){ 
      e.preventDefault(); 
      $form.attr('action',href); 
      $form.submit(); 
     } 
    }); 

    function isExternal(url) { 
     var match = url.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/); 
     if (typeof match[1] === "string" && match[1].length > 0 && match[1].toLowerCase() !== location.protocol) return true; 
     if (typeof match[2] === "string" && match[2].length > 0 && match[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"), "") !== location.host) return true; 
     return false; 
    } 
});</script> 
相關問題