I am using the FB PHP SDK to post a message to a user's wall. Once the user is authenticated via FB I allow them to post a message using this helper function
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.
But in Firebug I can see this error
<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:
$config = array(
'appId' => '123123123123',
'secret' => '567567567567'
);
$CI->load->library('facebook', $config);
$user_id = $CI->facebook->getUser();
Read more about the loader here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.