When trying the new Facebook WordPress plugin, I kept getting an error, the cause of the error was that I did not have the OpenSSL module configured for my PHP install, and there are several Facebook pages that the plugin tries to access using “https”.
Easy enough to fix.
When I didn’t have OpenSSL for my PHP the plugin was trying to throw an exception, but it couldn’t. It complained about wrong number of parameters for the exception method. I looked at the exception method signature and it was requiring a $msg and $code.
$msg is a string.
$code is an integer.
Here is the value of $msg that was being passed to the exception method when I did not have OpenSSL installed.
string(80) “There are no HTTP transports available which can complete the requested request.”
Here is the value for $code.
string(12) “http_failure”
$code was not an integer. This is what was causing the fatal error. So, I added a check before the the plugin called the constructor of parent of the exception class and made sure that if $code was not an integer then make $code = 0.
To fix this I had to make a change to facebook/includes/facebook-php-sdk/base_facebook.php, to the constructor of the FacebookApiException class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | class FacebookApiException extends Exception { /** * The result from the API server that represents the exception information. */ protected $result; /** * Make a new API Exception with the given result. * * @param array $result The result from the API server */ public function __construct($result) { $this->result = $result; $code = isset($result['error_code']) ? $result['error_code'] : 0; if (isset($result['error_description'])) { // OAuth 2.0 Draft 10 style $msg = $result['error_description']; } else if (isset($result['error']) && is_array($result['error'])) { // OAuth 2.0 Draft 00 style $msg = $result['error']['message']; } else if (isset($result['error_msg'])) { // Rest server style $msg = $result['error_msg']; } else { $msg = 'Unknown Error. Check getResult()'; } ////// // I added this to make sure $code is an integer ////// if(!is_int($code)) { $code = 0; } parent::__construct($msg, $code); } |
Cool, no more fatal errors, and once I installed OpenSSL I had a working plugin.