1

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!

Community
  • 1
  • 1
Adam Baney
  • 57
  • 1
  • 2
  • 11
  • What exact request are you making, and how often? What kind of access token are you using? – CBroe Oct 09 '15 at 21:15
  • 2
    Cache the results. Invalidate the cache periodically. This is one metric that nobody expects to be truly real time; within a minute is more than good enough. – Ghedipunk Oct 09 '15 at 21:21
  • Facebook's rate limit is 600 requests per 600 seconds... That is, you can make 600 requests in one second, but have to wait 5 minutes for your next one, or one request every second and never have to wait. – Ghedipunk Oct 09 '15 at 21:22
  • 1
    @Ghedipunk: _“Facebook's rate limit is 600 requests per 600 seconds”_ – not any more: https://developers.facebook.com/docs/graph-api/advanced/rate-limiting – CBroe Oct 09 '15 at 21:36
  • Thanks for the updated info, @CBroe – Ghedipunk Oct 09 '15 at 21:45
  • See updated question above. Thanks for all your useful info so far. It's good to know that FB decreased the number of requests to 200! – Adam Baney Oct 09 '15 at 23:09
  • So no caching at all. Go implement some form of caching. Research this if you don’t know how to do that. – CBroe Oct 09 '15 at 23:18
  • I know what caching is, I'm not sure how to do it, though. Do you know of some goof resources off the top of your head? If not, I'll do a Google search. – Adam Baney Oct 09 '15 at 23:46
  • 1
    The simplest way: Write the result to a file, and next time you read the data from that file, check how old it is – and based on that decide if you need to request “fresh” data, or show the data cached in the file. – CBroe Oct 10 '15 at 01:17
  • That process makes sense. I'll do some research. Thank you! – Adam Baney Oct 10 '15 at 02:32
  • @CBroe - Seems like this solution [(link)](http://stackoverflow.com/questions/11407514/caching-json-output-in-php#answer-11407678) may work, but I don't know how to combine it with my code above. – Adam Baney Oct 11 '15 at 05:58

0 Answers0