2

When getting Ads from Facebook using the php sdk like this:

$params = array(    
    'time_range' => array(
        'since' => date('Y-m-d', strtotime('-7 days')),
        'until' => date('Y-m-d', strtotime('-1 days')),
    ),
    'limit' => 10,
    'time_increment' => 1,
);

$ads = $account->getAds(
    array(
        AdFields::ID,
        AdFields::ADSET_ID,
        AdFields::NAME,
        AdFields::ADLABELS,
        AdFields::CREATED_TIME
    ),
    $params
);

The returned ads array contains elements with create_time back to february

It seems like the params are completely ignored.

According to the Facebook docs (https://developers.facebook.com/docs/marketing-api/reference/adgroup/#parameter)

and also the sdk Code

(https://github.com/facebook/facebook-php-business-sdk/blob/1eb51fddd9bbd4af239b5dd940e727216c0278a7/src/FacebookAds/Object/AdAccount.php#L791)

it seems like time_range should be supported.

Any clues on why my output array does not reflect my params

These are the open issues i found: https://developers.facebook.com/community/threads/592418868011048/

1
  • this is the new $param I tried with a non-nested array: $params = array( 'time_range[since]' => date('Y-m-d', strtotime('-2 days')), 'time_range[until]' => date('Y-m-d', strtotime('-1 days')), 'limit' => 1000, 'time_increment' => 1, ); Unfortunately, the resulted output number does not change Commented Nov 4 at 7:51

1 Answer 1

0

For anyone encountering this issue, I was able to get it to work using the following params:

$params = array(
            'filtering' => array(
                array(
                    'field' => 'created_time',
                    'operator' => 'GREATER_THAN',
                    'value' => strtotime($start_date)
                ),
            ),
            'limit' => 1000
        );

The Reason seems to be that time_range is only supported by the Insights API and not the Marketing API

Sign up to request clarification or add additional context in comments.

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
time_range is not working, i presented a working alternative params code to filter ads by their created time. This should be sufficient for anyone encountering this issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.