3

我正在使用 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>

知道我做错了什么吗?

4

1 回答 1

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

于 2012-05-31T03:22:51.470 回答