Facebook page videos views, likes and shares count get by using api
<?php
session_start();
require_once __DIR__ . '/Facebook/autoload.php';
$fb = new \Facebook\Facebook([
'app_id' => '1043464692766631',
'app_secret' => '370d7dee7ede9ab95f24a227b9311fad',
'default_graph_version' => 'v8.0',
]);
$pageid = **********;
$permissions = ['user_photos']; // optional
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken();
$accessToken ='**************';
if (isset($accessToken)) {
$headers = array("Content-type: application/json");
$url3 = "https://graph.facebook.com/v8.0/JnJ.Human.Health.Stages/videos?fields=title&access_token={$accessToken}";
$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch3, CURLOPT_URL, $url3);
curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch3, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch3, CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch3, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
$svl=curl_exec($ch3);
$result3=json_decode($svl,TRUE);
foreach ($result3['data'] as $vid)
{
$vid_idviews = $vid['id'].'/video_insights?fields=values&access_token='.$accessToken;
$vid_idlikes = $vid['id'].'/likes?summary=total_count&access_token='.$accessToken;
$vid_share = $pageid.'_'.$vid['id'].'?fields=shares&access_token='.$accessToken;
// print_r($result3);
$url1 = "https://graph.facebook.com/v8.0/{$vid_idlikes}";
$url = "https://graph.facebook.com/v8.0/{$vid_idviews}";
$url3 = "https://graph.facebook.com/v8.0/{$vid_share}";
//echo $url = "https://graph.facebook.com/v8.0/7445072142564121/video_insights?fields=values&access_token=EAAO1Bo5ZAF6cBAN9fN6tfEyMZBvTlZByLaDxCwrKS9pnlhHUtPZAkU2DW6j4UaKy2tfrkdlABAa3SMjZBWe2MMgzVOvedTPkZBgQlMvakP0h0Gx2zCG7AqodKqy4ZBOnRW0jZAhdWI4ZBuBoFO6HkISFL8uNCtSfhLM9xgOn9R6c6kQZDZD";
$ch4 = curl_init();
curl_setopt($ch4, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch4, CURLOPT_URL, $url3);
curl_setopt($ch4, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch4, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch4, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch4, CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch4, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch4, CURLOPT_SSL_VERIFYPEER, false);
$st4=curl_exec($ch4);
$result4=json_decode($st4,TRUE);
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch1, CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
$st1=curl_exec($ch1);
$result1=json_decode($st1,TRUE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$st=curl_exec($ch);
// print_r($st);
$result=json_decode($st,TRUE);
// echo "<pre>";
// print_r($result);
// echo "</pre>";
echo 'Video Id =' . $vid['id']. '<br>';
echo 'Video Title =' .$vid['title']. '<br>';
echo 'Likes count ='. $result1['summary']['total_count']. '<br>';
echo 'Views Count = '. ($result['data'][0]['values'][0]['value']). '<br>';
echo 'Shares Count = '. ($result4['shares']['count']). '<br>';
// $likes = $result['summary']['total_count'];
// echo "<center>";
// echo "<img width='700' height='450' src=https://scontent-kul1-1.xx.fbcdn.net/t31.0-8/15137500_10151131757949953_4183847601030332798_o.jpg><br><br>";
// echo "<img width='90' height='90' src=http://i.imgur.com/wVAJS8T.png>";
// echo "<h3>$likes</h3>";
// echo "</center>";
}
} else {
$loginUrl = $helper->getLoginUrl('https://xxx.xx.com/fb/', $permissions);
echo '<a href="' . $loginUrl . '">Login with Facebook</a>';
}