Este sitio web utiliza cookies para realizar análisis y mediciones de tus visitas. [ Acepto ] [ Más información aquí ].

How to use Facebook API

Facebook API can be used in PHP to measure the popularity of any website or webpage in Facebook. Specifically, to get the number of likes, comments, shares and clicks received by any website in Facebook. Do it with this simple PHP code, by replacing the URL address in bold letters:

$query = "select total_count,like_count,comment_count,share_count,click_count from

link_stat where url='www.thesartorialist.com'";

$call = "https://api.facebook.com/method/fql.query?query=" .

rawurlencode($query) . "&format=json";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $call);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec($ch);

curl_close($ch);

$stats = json_decode($output);

var_dump($stats);

Then, depending on the metric you'd like to extract, use one of these codes:

HOW TO GET NUMBER OF LIKES OF A WEBSITE IN FACEBOOK

Add this PHP code to retrieve the number of likes of any website in Facebook:

$likes = $stats->like_count;

echo $likes;

HOW TO GET THE NUMBER OF COMMENTS OF A WEBSITE IN FACEBOOK

Add this PHP code to retrieve the number of comments of any website in Facebook:

$comments = $stats->comment_count;

echo $comments;

HOW TO GET THE NUMBER OF SHARES OF A WEBSITE IN FACEBOOK

Add this PHP code to retrieve the number of shares of any website in Facebook:

$shares = $stats->share_count;

echo $shares;

HOW TO GET THE NUMBER OF CLICKS OF A WEBSITE IN FACEBOOK

Add this PHP code to retrieve the number of clicks of any website in Facebook:

$clicks = $stats->click_count;

echo $clicks;

Añadir comentario