简体   繁体   English

Facebook API 限速提升

[英]Facebook API rate limit increase

I'm working on a project which provide businesses to manage their facebook page, thus it will have tons of api call to Facebook.我正在开展一个项目,该项目为企业提供管理他们的 facebook 页面,因此它将有大量的 api 调用 Facebook。 Is that possible to increase the rate limit by special request?是否可以通过特殊要求提高速率限制?

Actually this is now possible... 实际上现在可以......

  1. Go to your Facebook App Developer Dashboard 转到您的Facebook App开发人员仪表板
  2. Scroll down to Application Level Rate Limiting 向下滚动到应用程序级别速率限制
  3. Click Request for Rate Increase 单击“提高费率请求”
  4. Fill out the request advising why you require the rate increase 填写请求,告知您需要加息的原因

Facebook App Developer Dashboard Facebook App开发人员仪表板

API Limit increase request API限制增加请求

No, there is no way to increase the limits by special request. 不,没有办法通过特殊要求增加限制。 If you really hit the limits, you are most likely doing something you are not supposed to. 如果你真的达到极限,你最有可能做一些你不应该做的事情。 It is no problem to let businesses manage their FB Page with their own Page Token. 让企业用他们自己的页面令牌管理他们的FB页面是没有问题的。

2022 Update: 2022 年更新:

Looks like there's no way to increase limits for your app:看起来没有办法增加您的应用程序的限制:

Based on Facebook best practices and on Goutham answer基于Facebook 最佳实践和 Goutham 答案

1 - When the limit has been reached, stop making API calls. 1 - 达到限制后,停止进行 API 调用。 Continuing to make calls will continue to increase your call count, which will increase the time before calls will be successful again.继续拨打电话将继续增加您的通话次数,这将增加通话再次成功的时间。

2 - Check the X-Business-Use-Case-Usage HTTP header to see how close your ad account is to its limit and when you can resume making calls. 2 - 检查 X-Business-Use-Case-Usage HTTP header 以查看您的广告帐户接近其限制的程度以及何时可以继续拨打电话。

3 - Verify the error code and API endpoint to confirm the throttling type. 3 - 验证错误代码和 API 端点以确认限制类型。

4 - Switch to other ad accounts and come back to this account later. 4 - 切换到其他广告帐户,稍后再返回此帐户。

5 - It is better to create a new ad than to change existing ones. 5 - 制作新广告比更改现有广告更好。

6 - Spread out queries evenly between two time intervals to avoid sending traffic in spikes. 6 - 在两个时间间隔之间平均分布查询以避免发送高峰流量。

7 - Use filters to limit the data response size and avoid calls that request overlapping data. 7 - 使用过滤器来限制数据响应大小并避免请求重叠数据的调用。

Personally, I have developed this little snippet to never reach the limit but I can make your execution extremely long.就个人而言,我开发了这个小片段以永远不会达到极限,但我可以让你的执行时间非常长。 (it's C#) (它是 C#)

    private void TrySleepIfApiLimitIsClose(HttpResponseMessage response)
    {
        try
        {
            IEnumerable<string> businessUsage = response.Headers.FirstOrDefault(header => header.Key == "x-business-use-case-usage").Value;
            IEnumerable<string> appUsage = response.Headers.FirstOrDefault(header => header.Key == "x-app-usage").Value;
            IEnumerable<string> adAccountUsage = response.Headers.FirstOrDefault(header => header.Key == "x-ad-account-usage").Value;
            IEnumerable<string> insightsUsage = response.Headers.FirstOrDefault(header => header.Key == "x-fb-ads-insights-throttle").Value;

            if (businessUsage != null)
            {
                IEnumerable<FacebookBusinessUseCaseUsage> usages = JsonConvert.DeserializeObject<IEnumerable<FacebookBusinessUseCaseUsage>>($"[{Regex.Match(businessUsage.First(), @"\[.{1,}\]").Groups[0].Value.Replace("[", string.Empty).Replace("]", string.Empty)}]");

                foreach (var usage in usages)
                {
                    if (usage.CallCount >= 80 ||
                        usage.TotalCpuTime >= 80 ||
                        usage.TotalTime >= 80)
                        Delay();
                }
            }

            if (appUsage != null)
            {
                FacebookBusinessUseCaseUsage usage = JsonConvert.DeserializeObject<FacebookBusinessUseCaseUsage>(appUsage.First());

                if (usage.CallCount >= 80 ||
                    usage.TotalCpuTime >= 80 ||
                    usage.TotalTime >= 80)
                    Delay();
            }

            if (adAccountUsage != null)
            {
                int usage = int.Parse(Regex.Match(adAccountUsage.First(), @"\d{1,}").Groups[0].Value);

                if (usage >= 80)
                    Delay();
            }

            if (insightsUsage != null)
            {
                FacebookAdInsightsThrottle usage = JsonConvert.DeserializeObject<FacebookAdInsightsThrottle>(insightsUsage.First());

                if (usage.AppIdUtilPct >= 80 || usage.AccIdUtilPct >= 80)
                    Delay();
            }
        }
        catch { }
    }

Delay a few minutes:延迟几分钟:

private void Delay() => Thread.Sleep(1000 * 200);

Note that I swallow the exception because I don't want to break my execution, in my case it's better to reach the limit than break the execution.请注意,我吞下了异常,因为我不想中断执行,在我的情况下,达到限制比中断执行更好。 Also be careful with Thread.Sleep you have to consider your context (multi-thread? async? … ).还要小心Thread.Sleep你必须考虑你的上下文(多线程?异步?...)。

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

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