Shares only
1 2 3 4 5 |
function get_likes($url) { $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url); $json = json_decode($json_string, true); return intval( $json[$url]['shares'] ); } |
Shares & Likes
1 2 3 4 5 6 7 8 9 10 11 12 |
function get_likes($url) { $json_string = file_get_contents(‘http://graph.facebook.com/?ids=’ . $url); $json = json_decode($json_string, true); $like_count = 0; if (isset($json[$url]['shares'])) $like_count += intval($json[$url]['shares']); if (isset($json[$url]['likes'])) $like_count += intval($json[$url]['likes']); return $like_count; } |