Obtener Facebook likes ó shares con PHP

El siguiente código con PHP obtiene el número de “Me gusta” ó “Compatir” de Facebook, incluso número de comentarios de cualquier URL que proporciones.

share like

<?php
function facebook_shares($url){
    $fql  = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
    $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
    $fql .= "link_stat WHERE url = '".$url."'";
    $apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
    $fb_json=file_get_contents($apifql);
    return json_decode($fb_json);
}
$fb = facebook_shares('https://www.ribosomatic.com/articulos/tutorial-aplicacion-web-con-jquery-php-mysql-mantenimiento-de-datos/');
// facebook share count
echo $fb[0]->share_count.'<br />';
// facebook like count
echo $fb[0]->like_count.'<br />';
// facebook comment count
echo $fb[0]->comment_count.'<br />';
?>

Vía PaperMashup

One thought on “Obtener Facebook likes ó shares con PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Wanderz Blog by Crimson Themes.