Writing a wordpress plugin and trying to include the Facebook PHP SDK
I'm writing a plugin for WordPress that required the Facebook PHP SDK. I've run into what I think is a common problem judging from the number of results I've found dating back to over a year ago. Unfortunately, I have been unable to find a solution.
I'm using WordPress 3.8 and Facebook PHP SDK Master taken from github so this should be the latest version. I've actually run this same code outside of WordPress and it successfully ran with no errors.
So, i upload my plugin and activate it. I go to the panel I've built that asks for the appID and Secret key and also the username for the facebook account. All the plugin will do is grab the username me feed.
So, when i try to run the primary function that loads the feed I get the following errors:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at {path}/wp-admin/includes/template.php:1698) in {path}/wp-content/plugins/{mypluginname}/facebook-php-sdk/src/facebook.php on line 48
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at {path}/wp-admin/includes/template.php:1698) in {path}/wp-content/plugins/{mypluginname}/facebook-php-sdk/src/facebook.php on line 48
What I've tried
So, I've read in a few different posts that I should use ob_start() and ob_end_flush() php functions and that will fix the problem. As i understand the problem I am having I am sending things to the header where I shouldnt because the header has already been sent.
I've tried ob_start / ob_end_flush at the top and bottom of my plugin and it made no different.
I've tried downloading the Facebook wordpress plugin and using the modified Facebook PHP SDK that that plugin uses and that got rid of those errors but created a new error.
Fatal error: Access to undeclared static property: WP_BaseFacebook::$CURL_OPTS in {path}/wp-content/plugins/{pluginname}/facebook-php-sdk/src/base_facebook.php on line 932
So, I read that this is because CURL is not enabled. I've checked my PHP INFO page and CURL is enabled. I use curl requests in another plugin. I do see certain things under the CURL features that are not enabled. Does anyone know which option I need to enable to get this modified version of the Facebook PHP SDK to work with my plugin?
Does anyone know how to fix either the errors I am getting from the standard Facebook PHP SDK OR does someone know how to fix the errors I am getting from modified Facebook PHP SDK?
Thanks in advance. I hope to get a solution to both worked and then finally put this issue to rest. We've been plagued with this same problem since 2011.
In order to provide some more details, here is part of the code I have in my plugin.
require_once('facebook-php-sdk/src/facebook.php');
global $facebook; // read that i needed to add this line to my script; it didnt help.
// Create our Application instance (replace this with your appId and secret).
$fb_config = array(
'appId' => $ijFaceFeedAppID,
'secret' => $ijFaceFeedSecretKey,
'fileUpload' => false,
'allowSignedRequest' => false
);
// get feed
$facebook = new WP_Facebook($fb_config); // am using the modified facebook sdk
$page_feed = $facebook->api(
'/'.$ijFaceFeedUser.'/feed',
'GET'
);