FB API to Pull the Like and Share Statistics for a URL

By fathimath.sajila | 27th November 2017 | 1 min read

Here we describe the steps to find number of likes and shares for an article listed on your website. We can pull the count of like and share for a URL using API links:


The json response is like this


Checkout the article to find the steps to create a Facebook App. We can also pull the like and share statistics using PHP Facebook SDK. For this purpose we need the following.

  1. Download PHP Facebook SDK.
  2. Include autoload.php in all sample of thecode.

Let's look at a simple example:

require_once __DIR__ . '/your_path/src/Facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
$session = new FacebookSession('YOUR_ACCESS_TOKEN');
try {
  $request = new FacebookRequest(
  array (
    'id' => 'http://www.mywebsite.com',
  $response = $request->execute();
  $graphObject = $response->getGraphObject();
catch (\Exception $e) {

Hope this helps.