2012-05-31 141 views
3

我正在使用FB PHP SDK將消息發佈到用戶的牆上。 一旦用戶通過驗證FB我允許他們使用這個輔助函數Codeigniter和Facebook PHP SDK - 發佈到用戶牆上的錯誤

function post_facebook($fb) { 

    $CI =& get_instance(); 

    $CI->load->library('facebook'); 

    $config = array(
     'appId' => '123123123123', 
     'secret' => '567567567567' 
    ); 

    $facebook = new Facebook($config); 
    $user_id = $facebook->getUser(); 

    if ($user_id) { 

     $facebook->api('/me/feed', 'POST', array(
               'message' => $fb['post_text'], 
              ) 
        ); 
    } 
} 

這實際上發出的帖子FB和它顯示在牆壁上張貼的消息。

但在Firebug我可以看到這個錯誤

<h4>A PHP Error was encountered</h4> 

<p>Severity: Warning</p> 
<p>Message: Missing argument 1 for Facebook::__construct(), called in /var/www/vhosts/example.com/httpdocs/system/core/Loader.php on line 1099 and defined</p> 
<p>Filename: libraries/Facebook.php</p> 
<p>Line Number: 36</p> 

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> 

<h4>A PHP Error was encountered</h4> 

<p>Severity: Notice</p> 
<p>Message: Undefined variable: config</p> 
<p>Filename: libraries/Facebook.php</p> 
<p>Line Number: 40</p> 

</div> 

任何想法,我做錯了嗎?

回答

9

您所看到的錯誤是從呼叫$this->load->library('facebook'),你應該通過$配置陣列作爲參數傳遞給它,並從CI對象訪問庫,就像這樣:

$config = array(
    'appId' => '123123123123', 
    'secret' => '567567567567' 
); 
$CI->load->library('facebook', $config); 

$user_id = $CI->facebook->getUser(); 

瞭解更多關於裝載機在這裏:

http://codeigniter.com/user_guide/libraries/loader.html

+1

完美,感謝了一堆 – pepe

+0

歡迎您! :) – elias

相關問題