FIX FOR ‘FACEBOOK ERROR: INVALID OAUTH ACCESS TOKEN’ ERROR WITH API V2.3

Today Facebook ended support for v2.2 of the API, and v2.3 includes a change to the format of access tokens which broke the ‘Add Link to Facebook’ plugin and generates the access token error above.

After a little debugging, I found a fix by editing the add-link-to-facebook-int.php file:

Replace

static function Process_fb_token($response) {
	$key = 'access_token=';
 	$access_token = substr($response, strpos($response, $key) + strlen($key));
	$access_token = explode('&', $access_token);
	$access_token = $access_token[0];
	return $access_token;
}

with

static function Process_fb_token($response) {
	$key = 'access_token=';
	$access_token = json_decode($response)->access_token;
//	$access_token = substr($response, strpos($response, $key) + strlen($key));
//	$access_token = explode('&', $access_token);
//	$access_token = $access_token[0];
	return $access_token;
}