当我在Laravel应用中调用此函数以获取有关我的Facebook Ads效果的细分报告时,经常会遇到此错误(FacebookAds\Http\Exception\AuthorizationException, Code: 17: (#17) User request limit reached
。
/**
* @param string $levelType
* @param string $id
* @param string $start (YYYY-MM-DD date)
* @param string $end (YYYY-MM-DD date)
* @param int $minImp
* @return array
*/
public function getFbBreakdown($levelType, $id, $start, $end, $minImp = 100) {
$cacheKey = 'fbBreakdown' . $levelType . $id . $start . $end . $minImp;
return Cache::remember($cacheKey, 60, function () use ($levelType, $id, $start, $end, $minImp) {
$fields = [
strtolower(self::SPEND),
AdsInsightsFields::IMPRESSIONS
];
$params = [
'breakdowns' => self::AD_ACCT_HOURLY_STATS,
];
$dateRanges = $this->fbTools->getDateRangeBrokenDownToDays($start, $end);
foreach ($dateRanges as $range) {
$params[AdReportRunFields::TIME_RANGE] = $range;
$endpoint = '/' . $id . '/insights?' . 'fields=' . implode(',', $fields);
$fbr = new FacebookRequest($this->fbApp, $this->fbConfig[self::ACCESS_TOKEN], \FacebookAds\Http\RequestInterface::METHOD_GET, $endpoint, $params, null, self::FB_GRAPH_VERSION);
$requests[] = $fbr;
}
$batches = array_chunk($requests, 50); //Facebook limits batch requests to 50 at a time
$chunkedFbResponses = [];
foreach ($batches as $batchOfRequests) {
$response = $this->fb->sendBatchRequest($batchOfRequests, $this->fbConfig[self::ACCESS_TOKEN]);
$chunkedFbResponses[] = $response->getResponses();
}
$responses = [];
foreach ($chunkedFbResponses as $chunkedFbResponse) {
$responses = array_merge($responses, $chunkedFbResponse);
}
return $responses;
});
}
在https://developers.facebook.com/apps/99999/dashboard/?business_id=99999的Facebook开发人员仪表板中,我看到已达到“广告帐户费率限制”,但对“用户请求限制”却一无所获。 是同一回事吗?
我知道限制似乎每5分钟就会重置一次。
每5分钟允许多少次查询?
我还有其他方法可以更好地对查询进行批处理,以使该函数使用更少的API请求吗?
答案 0 :(得分:1)
广告帐户级别和用户级别均抛出错误代码17。每5分钟允许的查询量基于广告帐户,Facebook并未实际解释其确定方式,但我确实记得在某处读过与帐户上的广告支出相关联。以编程方式弄清楚其速率限制的工作实际上违反了他们的服务条款。
分批对速率限制完全没有帮助。最好的办法是插入标头x-ad-account-usage
,一旦命中率很高,就进入睡眠状态。
查看最佳做法页面: https://developers.facebook.com/docs/marketing-api/best-practices