Skip to content

This PHP script uses the Facebook Graph API to retrieve engagement metrics for a specific domain, including likes, shares, and comments.

Notifications You must be signed in to change notification settings

VolkanSah/Facebook-Domain-Metrics-Checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Facebook-Domain-Metrics-Checker

This PHP script uses the Facebook Graph API to retrieve engagement metrics for a specific domain, including likes, shares, and comments.

  • Code example in PHP that uses the Facebook Graph API to retrieve the number of likes, shares, and comments for a specific domain.
$access_token = "your-access-token";
$domain = "https://example.com";

$request_url = "https://graph.facebook.com/v13.0/?id=" . urlencode($domain) . "&fields=engagement&access_token=" . $access_token;

$response = file_get_contents($request_url);
$json = json_decode($response, true);

$likes = $json['engagement']['reaction_count'];
$shares = $json['engagement']['share_count'];
$comments = $json['engagement']['comment_count'];

echo "Likes: " . $likes . "<br>";
echo "Shares: " . $shares . "<br>";
echo "Comments: " . $comments . "<br>";

or use Facebook PHP SDK

{
  "require": {
    "facebook/graph-sdk": "^7.0"
  }
}
composer install
require_once 'path/to/facebook-php-sdk/autoload.php';

use Facebook\Facebook;

$access_token = 'your-access-token';
$domain = 'https://example.com';

$fb = new Facebook([
  'app_id' => 'your-app-id',
  'app_secret' => 'your-app-secret',
  'default_graph_version' => 'v13.0',
  'default_access_token' => $access_token,
]);

try {
  $response = $fb->get('/?id=' . urlencode($domain) . '&fields=engagement');
  $json = $response->getDecodedBody();

  $likes = $json['engagement']['reaction_count'];
  $shares = $json['engagement']['share_count'];
  $comments = $json['engagement']['comment_count'];

  echo "Likes: " . $likes . "<br>";
  echo "Shares: " . $shares . "<br>";
  echo "Comments: " . $comments . "<br>";
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
}

copyright Volkan Sah

About

This PHP script uses the Facebook Graph API to retrieve engagement metrics for a specific domain, including likes, shares, and comments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages