I am building a Facebook page like counter. I want to be able to get page like updates roughly every 2-3 seconds. The result will be sent to a sql database then sent to an Arduino. First of all though, I need to get the likes from the desired page. I have the PHP script below that works great but you have to load the page every time to get an updated like count.
Would you be able to use a while loop with some sort of 2-3 second delay? or what you recommend in situation? p.s I used Dan Bilzerian's FB page as an example because his likes just keep going up up up, its ridiculous.
Thanks
function facebook_count($url){
// Query in FQL
$fql = "SELECT like_count";
$fql .= " FROM link_stat WHERE url = '$url'";
$fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);
// Facebook Response is in JSON
$response = file_get_contents($fqlURL);
return json_decode($response);
}
$fb = facebook_count('https://www.facebook.com/danbilzerianofficial');
// facebook like count
echo $fb[0]->like_count;
</div>