facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
818 stars 514 forks source link

Issue with throttle header (x-fb-ads-insights-throttle) #483

Closed vstruhar closed 5 years ago

vstruhar commented 5 years ago

Hello,

I have noticed an issue when making requests, that the response header has: {"app_id_util_pct":0,"acc_id_util_pct":0}

And the app_id_util_pct parameter goes only up to 0.01 and then unexpectedly I get a AuthorizationException with a code 17, which is "User request limit reached"

I was expecting that limit will be reached when app_id_util_pct or acc_id_util_pct parameter end up at 100.

Insights Call Load Limits: https://developers.facebook.com/docs/marketing-api/insights/best-practices/

Am I missing something?

Denis4yk commented 5 years ago

Hm...on my project I have the same issue. +1 for the question

jingping2015 commented 5 years ago

Did you try same curl call to check if the api call get the same response ?

vstruhar commented 5 years ago

Didn't try to make a clean curl request.

Here is a simplified code example of how facebook-php-business-sdk was used.


Api::init($this->account->api_key, $this->account->api_password, $this->account->access_token);

$adAccount = new AdAccount('act_' . $this->account->account_id);

$fields = [AdsInsightsFields::SPEND, ... ];

$params = [
    'time_range'     => [
        'since'      => $startDate,
        'until'      => $endDate,
    ],
    'time_increment' => 1,
    'breakdowns'     => [AdsInsightsBreakdownsValues::COUNTRY],
    'limit'          => 200,
];

try {
    $insightsRequest = $adAccount->getInsights($fields, $params);
} catch (AuthorizationException $e) {
    if ($e->getCode() == 17) {
        Log::warning("Account request limit reached", [
            'x-fb-ads-insights-throttle' => json_decode($insightsRequest->getLastResponse()->getHeaders()['x-fb-ads-insights-throttle'], 1)
        ]);
    }
}
jingping2015 commented 5 years ago

Hi, please add

$api = Api::instance();
$api->setLogger(new CurlLogger());

on top of your request, and then there will be a curl be printout for you. Then you can use the curl request to make api call directly. This is actually an api issue. Please report the issue on Devsite Bug Report channel: https://developers.facebook.com/support/bugs/ Thanks!