简体   繁体   English

突然的 Facebook API 速率限制错误(试图获取共享计数)

[英]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.几个月来,我一直在使用相同的代码来获取我网站上页面的 Facebook 共享计数。 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.在浏览器中尝试源代码 URL 后,我意识到它抛出了 API 限制错误。 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 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 =访问权限

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. #613) 对 graph_url_engagement_count 的调用已超过每 3600 秒 10 次调用的速率。

They recently changed this.他们最近改变了这一点。

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

You are limited to 10 GET requests per URL, per app, per hour.每个应用程序每小时每个 URL 限制为 10 个 GET 请求。

It also says:它还说:

"Note that engagement values are intentionally not precise, but you can be confident they accurately reflect user engagement with a URL." “请注意,参与度值故意不精确,但您可以确信它们准确地反映了 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.您正在总结所有参与计数,因此您可能想尝试访问“og_object {engagement}”字段而不是“参与”,它似乎不受速率限制的影响。 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 ):除了速率限制问题,更大的问题是他们在 2021 年 5 月 25 日推出的 Graph API 更改。版本 10 及更高版本现在有这个新规定( 来源):

Due to privacy concerns, counts returned by a GET /?id={url}/engagement request may not match raw counts.由于隐私问题,GET /?id={url}/engagement 请求返回的计数可能与原始计数不匹配。

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. Facebook 团队在一些错误报告中回应说,参与次数少于 100 的帖子将不再显示任何数据。 While that is fine, it isn't accurate, as I have some posts with more than 100 engagements that are still returning nothing.虽然这很好,但并不准确,因为我有一些帖子有超过 100 次参与,但仍然没有返回任何内容。

在此处输入图像描述

Some posts with 100+ engagements still do return data.一些参与度超过 100 次的帖子仍然会返回数据。 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. Facebook 似乎并没有花时间在他们的最后进行正确的测试。

I've commented on some of the Facebook bug reports, along with others, as we are hoping to get some better answers from Facebook.我已经评论了一些 Facebook 错误报告以及其他错误报告,因为我们希望从 Facebook 获得更好的答案。

I also wrote up a longer summary here: https://novashare.io/docs/facebook-share-counts-graph-api-v10/我还在这里写了一个更长的摘要: https://novashare.io/docs/facebook-share-counts-graph-api-v10/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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