2011-08-10 13 views
0

まあ、私はちょうど私のスクリプトを更新しようと、私は(のgetUser 0のリターンを得続ける)ここPHP SDK 3.1.1とJS SDKのgetUser()0

iは

を変えカップルの抜粋ですを返します

古いコード

<?php 

require_once("src/facebook.php"); 

class cfb 
{ 
    public $fb; 
    public $_fb_user; 
    public $_fb_details; 
    public $_fb_app_id   = '**************'; 
    private $_fb_app_secret  = '***************'; 
    private $_user; 

    function __construct() 
    { 
     $this->fb = new Facebook(array(
     'appId' => $this->_fb_app_id, 
     'secret' => $this->_fb_app_secret, 
     'cookie' => true, 
     )); 

     $this->_fb_user = $this->fb->getSession(); 

     $this->DB = new db(); 
     $this->_user = new user(); 
    } 

    public function session_exists() 
    { 

     // see if there is a session stored, if so make sure the session is still good on facebooks end 
     if($this->_fb_user) { 

      // test if session is still good 
      try 
      { 
       $me = $this->fb->api('/me'); 
      } 
      catch(FacebookApiException $e){ 

       error_log($e); 

      } 

      if(!empty($me)) { 

       return true; 

      } 

     } else { 

      return false; 

     } 
    } 

新しいコード

<?php 

require_once("src/facebook.php"); 

class cfb 
{ 
    public $fb; 
    public $_fb_user; 
    public $_fb_details; 
    public $_fb_app_id   = '*****************'; 
    private $_fb_app_secret  = '********************'; 
    private $_user; 

    function __construct() 
    { 
     $this->fb = new Facebook(array(
     'appId' => $this->_fb_app_id, 
     'secret' => $this->_fb_app_secret, 
     )); 

     $this->_fb_user = $this->fb->getUser(); 

     $this->DB = new db(); 
     $this->_user = new user(); 
    } 

    public function session_exists() 
    { 

     // see if there is a session stored, if so make sure the session is still good on facebooks end 
     if($this->_fb_user) { 

      // test if session is still good 
      try 
      { 
       $me = $this->fb->api('/me'); 
      } 
      catch(FacebookApiException $e){ 

      echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>'; 

      } 

      if(!empty($me)) { 

       return true; 

      } 

     } else { 

      return false; 

     } 
    } 

ここで私はそれを把握することはできません

<div id="fb-root"></div> 
    <script> 
     window.fbAsyncInit = function() { 
     FB.init({ 
      appId : '<?php echo $fb->_fb_app_id; ?>', 
      status : true, // check login status 
      cookie : true, // enable cookies to allow the server to access the session 
      xfbml : true // parse XFBML 
     }); 

     // whenever the user logs in, we refresh the page 
     FB.Event.subscribe('auth.login', function(response) { 
      window.location="<?php echo $fbredirect; ?>"; 
     }); 
     }; 

     (function() { 
     var e = document.createElement('script'); e.async = true; 
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
     document.getElementById('fb-root').appendChild(e); 
     }()); 


    </script> 

私のjsのコードがあります。それは簡単な更新が期待されていたが、私はそう思わない=/

答えて

2

あなたのJSコードにFB.initの機能の中にoauth:trueを追加してください。

あなたはここの例ではJS SDKでの作業PHP SDKのv.3.1.1を見ることができます:https://developers.facebook.com/blog/post/534/

+0

ありがとうございました!新しいJS SDKを使って「パーマ」を取得する方法も知っていますか? アップグレード後にが動作しません。 –

+0

私は "範囲"に変更しようとしましたが、それは動作しません –

+0

@ClintChaney v3.1.1はgetSession()の代わりにgetUser()を使用するため、 – sonnb

関連する問題