After reading this question’s accepted answer, I’m pretty sure that I’m having the same issue: Facebook is blocking my IP, as my site is performing “too many” requests. Is there a way to either whitelist my IP, or retrieve Facebook’s shares for a particular URL somehow without this issue occurring?
I’m using this functionality in a WordPress plugin, and this plugin will be used on multiple sites, each with their own IPs.
Thank you!
/ / / / / EDIT (10/9/2015, 5:07 MST)
I should have known that code would help:
<?php
////////// FACEBOOK - SHARES //////////
function getFacebookShares($url)
{
$url = get_permalink($post_id);
$title = get_the_title($post_id);
$facebookcount = json_decode( file_get_contents( 'https://graph.facebook.com/?id='.$url ) );
return $facebookcount->shares;
}
function FacebookShareCount($url)
{
if(getFacebookShares($url) > 0){
return number_format(getFacebookShares($url));
}else{
return 'Share';
};
}
function fb_social_share_btn()
{ ?>
<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" class="social-popup" data-popup="width=600,height=300">
<div class="social-item">
<span class="fa fa-facebook-official" data-count="<?php echo FacebookShareCount($url); ?>" data-social="fb"></span>
</div>
</a>
<?php
}
?>
The Facebook share count seems to display for about a day, then stops, and gives me that error message above. I’ve tested this with 2 different URLs.
You guys are great. Thanks!