简体   繁体   中英

Sudden Facebook API Rate Limit Error (Trying to Get Share Count)

I've looked at a ton of related posts here and can't seem to find an answer. I've been using the same code for months to get the Facebook share count of pages on my website. It's worked [relatively] flawlessly, but suddenly it started returning nothing. After trying the source URL in the browser, I realized it's throwing an API Limit error. Please help...

CODE:

[[[FUNCTION]]]
    return jQuery.ajax({
        url: 'https://graph.facebook.com/?fields=engagement&callback=FB.Share&id=' + permalinkWPSC + '&access_token=[[[ACCESS TOKEN]]]',
        type: 'GET',
        dataType: 'JSONP',
        success: function(data) {           
            count = 0;
            if (data.engagement) {  
                var count = Number(data.engagement.reaction_count + data.engagement.share_count + data.engagement.comment_count);
                var share_count_http = 0;
                if ($('[data-share-count]').length > 0) {
                    share_count_http = parseInt($('[data-share-count]').data('share-count'));
                }
                count = count + share_count_http;
            }

            $( ".share-num" ).html( count );
            $( "span.fbCount" ).html( count );
        }
    });
[[[END FUNCTION]]]

So this is essentially using this URL string (with "URL" being actual URL and "ACCESSTOKEN" being the access token granted by the Facebook API: https://graph.facebook.com/?fields=engagement&callback=FB.Share&id=URL&access_token=ACCESSTOKEN

ERROR:

/**/ FB.Share({
   "error": {
      "message": "(#613) Calls to graph_url_engagement_count have exceeded the rate of 10 calls per 3600 seconds.",
      "type": "OAuthException",
      "code": 613,
      "fbtrace_id": "Ad9vIHStlvzuGptF9LZmT-L"
   }
});

Note that nothing else changed on the website or with traffic. Very strange...

The answer is in the error message:

#613) Calls to graph_url_engagement_count have exceeded the rate of 10 calls per 3600 seconds.

They recently changed this.

The api documentation ( https://developers.facebook.com/docs/graph-api/reference/v10.0/url ) says:

You are limited to 10 GET requests per URL, per app, per hour.

It also says:

"Note that engagement values are intentionally not precise, but you can be confident they accurately reflect user engagement with a URL."

In practice this seems to mean if the likes, shares or comments are below a certain number it shows up as zero.

You're summing up all engagement counts, so you might want to try accessing 'og_object{engagement}' field instead of 'engagement', it doesn't seem to be affected by rate limits. EDIT: Here's your code edited to work with that.

[[[FUNCTION]]]
    return jQuery.ajax({
        url: 'https://graph.facebook.com/?fields=og_object{engagement}&callback=FB.Share&id=' + permalinkWPSC + '&access_token=[[[ACCESS TOKEN]]]',
        type: 'GET',
        dataType: 'JSONP',
        success: function(data) {           
            count = 0;
            if (data.og_object) {  
                var count = Number(data.og_object.engagement.count);
                var share_count_http = 0;
                if ($('[data-share-count]').length > 0) {
                    share_count_http = parseInt($('[data-share-count]').data('share-count'));
                }
                count = count + share_count_http;
            }
            $( ".share-num" ).html( count );
            $( "span.fbCount" ).html( count );
    });
[[[END FUNCTION]]]

Along with the rate limit issue, the bigger problem is with the Graph API change that they pushed out on May 25th, 2021. Version 10 and above now have this new stipulation ( source ):

Due to privacy concerns, counts returned by a GET /?id={url}/engagement request may not match raw counts.

However, it doesn't end there. The Facebook team has responded in a few bug reports that posts with fewer than 100 engagements will no longer show any data. While that is fine, it isn't accurate, as I have some posts with more than 100 engagements that are still returning nothing.

在此处输入图像描述

Some posts with 100+ engagements still do return data. The bigger problem is, the inaccuracy I'm seeing. It doesn't seem like Facebook is even taking the time to test this properly on their end.

I've commented on some of the Facebook bug reports, along with others, as we are hoping to get some better answers from Facebook.

I also wrote up a longer summary here: https://novashare.io/docs/facebook-share-counts-graph-api-v10/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM