Thursday, January 6, 2022

[FIXED] Getting "Invalid parameter" exception on getReportsStats with no reason

Issue

Can anyone help me with a fast code review?

$fields = array(
    'campaign_id',
    'spend'
);
$params = array(
    'data_columns' => $fields,
    'time_interval' => array(
        'day_start' => array(
            'year' => 2011,
            'month' => 9,
            'day' => 1
        ),
        'day_stop' => array(
            'year' => 2011,
            'month' => 9,
            'day' => 10
        ),
    ),
);
$stats = $adAccount->getReportsStats(array(), $params);

After running this code I am getting:

<b>Fatal error</b>:  Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /home/maciekmp/public_html/face_test/FacebookAds/Http/Exception/RequestException.php:129
fdfd

Solution

I found the following in the facebook api developer docs. Search on "async". If the data you are querying is too old you will have to do an asynchronous call to the graph api. Which is usually the case with the error you received. The current version of the php-sdk does not support passing an async parameter out of the box. Since AdAccount defaults to GET request and async calls to the graph api must be done with POST request, you will need to extend the AdAccount class and create and prepare a request to use the POST method.



Answered By - Rodney

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.