Codeigniter和Facebook PHP SDK - 错误发布到用户墙

时间:2012-05-31 03:08:31

标签: php codeigniter facebook-graph-api facebook-php-sdk

我正在使用FB PHP SDK将消息发布到用户的墙上。 一旦用户通过FB进行身份验证,我就允许他们使用此帮助函数发布消息

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>

知道我做错了吗?

1 个答案:

答案 0 :(得分:9)

您看到的错误来自对$this->load->library('facebook')的调用,您应该将$ config数组作为参数传递给它并从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