简体   繁体   English

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

[英]Codeigniter and Facebook PHP SDK - error posting to user wall

I am using the FB PHP SDK to post a message to a user's wall. 我正在使用FB PHP SDK将消息发布到用户的墙上。 Once the user is authenticated via FB I allow them to post a message using this helper function 一旦用户通过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'],
                                           )
                   );
     }
}

This actually sends the post to FB and it shows on the wall. 这实际上是将帖子发送给FB,它显示在墙上。

But in Firebug I can see this error 但是在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>

Any idea what I'm doing wrong? 知道我做错了什么吗?

The error you see is from the call to $this->load->library('facebook') , you should pass the $config array as a parameter to it and access the library from the CI object, like this: 您看到的错误来自对$this->load->library('facebook')的调用,您应该将$ config数组作为参数传递给它并从CI对象访问库,如下所示:

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

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

Read more about the loader here: 在这里阅读有关装载机的更多信

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM