Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ad-inserter domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/blog.webeats.it/httpdocs/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cookie-law-info domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/blog.webeats.it/httpdocs/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/blog.webeats.it/httpdocs/wp-includes/functions.php on line 6114
PHP: accedere al conteggio dei like, commenti e share di un link con le API Facebook - Blog WebEats

PHP: accedere al conteggio dei like, commenti e share di un link con le API Facebook

Tramite le API di Facebook possiamo facilmente fare una query al Database di Facebook per leggere delle informazioni. Includendo questa semplice funzione nel nostro codice possiamo accedere facilmente al conteggio dei Like, Commenti e Share


function fb_count($url){
$fql = "SELECT share_count, like_count, comment_count ";
$fql .= " FROM link_stat WHERE url = '$url'";
$fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);
$response = file_get_contents($fqlURL);
return json_decode($response);
}

Ora richiamiamo la funzione appena scritta

$fb = fb_count('https://blog.webeats.it');

E poi accediamo a share_count, like_cont e comment_count

echo $fb[0]->share_count;
echo $fb[0]->like_count;
echo $fb[0]->comment_count;