How to Get Last Updated Facebook Ads
To retrieve Facebook ads that have been updated recently, utilize the filtering
parameter. Here's how to do it:
Filtering Parameter
The filtering
parameter allows you to filter various ad objects (campaigns, ad sets, and ads) based on their updated_time
field. The syntax for the filtering
parameter is as follows:
filtering=[{field: "<object>.updated_time", operator: "GREATER_THAN", value: <unix time>}]where: *
<object>
represents the ad object you want to filter (e.g., "campaign", "adset", or "ad")
* GREATER_THAN
is the comparison operator indicating that the updated time should be greater than the specified value
* <unix time>
is the Unix time (in seconds) representing the time after which you want to retrieve updated ads
Example: Get Campaigns Updated After a Specific Time
To fetch all campaigns updated after a specific Unix time (e.g., 2018-02-01
), use the following cURL command:
curl -G \ -d 'access_token=<ACCESS_TOKEN>' \ -d 'filtering=[{field:"campaign.updated_time",operator:"GREATER_THAN",value:1517443200}]' \ 'https://graph.facebook.com/v2.12/act_<ACCOUNT_ID>/campaigns'
Note:
In Python, you can use the GraphAPI.get_objects()
method to retrieve ad objects with the filtering
parameter.
For example, to filter ad sets updated in the last one day, you can use the following code:
import facebook import datetime graph = facebook.GraphAPI(access_token='YOUR_ACCESS_TOKEN') params = { 'filtering': [ { 'field': 'adset.updated_time', 'operator': 'GREATER_THAN', 'value': (datetime.datetime.now() - datetime.timedelta(days=1)).timestamp() } ] } adsets = graph.get_objects('act_YOUR_ACCOUNT_ID/adsets', fields='id,name,updated_time', **params)