How to Store Facebook Like Count in Database

$node_id='nid of page';
$data_url='url of the webpage which you want to save in db';
$fql = "SELECT url, share_count, like_count, comment_count, total_count FROM link_stat WHERE url='$data_url'";
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query='.urlencode($fql));
$fblike=json_decode($json);
$fbcount=intval($fblike[0]->total_count);
$rec=db_query("INSERT INTO tablename (nid, count) VALUES ($node_id,$fbcount) ON DUPLICATE KEY UPDATE count=$fbcount");

No comments:

Post a Comment