How can i define a filter for Facebook Marketing API for the method get_lead_gen_forms? I have tried passing some params, but nothing works.
I need to filter by date because the number of data is exceeding my limit. Here's my code (* the code already works, need help with the filter):
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
account = AdAccount('act_accountid')
leadgenforms = account.get_lead_gen_forms()
And here is the params that i have tried:
# attempt 1
params = {
'time_range': {
'since': date_start,
'until': date_end
}
}
leadgenforms = account.get_lead_gen_forms(params=params)
# attempt 2
params = {
'filtering': [{
'field': 'created_time',
'operator': 'GREATER_THAN',
'value': date_start }]
}
leadgenforms = account.get_lead_gen_forms(params=params)
答案 0 :(得分:0)
您应该过滤字段time_created
而不是created_time
。
在doc here的筛选线索部分中:
此示例根据时间戳过滤销售线索。时间戳记应为 Unix时间戳。
curl -G \ --data-urlencode 'filtering=[ { "field": "time_created", "operator": "GREATER_THAN", "value": 1516682744 } ]' \ -d 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v2.11/<AD_ID>/leads
因此,在第二个尝试示例中:
# attempt 2
params = {
'filtering': [{
'field': 'time_created',
'operator': 'GREATER_THAN',
'value': date_start }]
}
leadgenforms = account.get_lead_gen_forms(params=params)
您应在广告date_start
中使用以unix时间戳记格式显示的日期:
自Unix纪元以来的秒数
希望获得帮助