Python - How to filter on Facebook Marketing API AdAccount.get_lead_gen_forms?

时间:2018-11-06 20:14:58

标签: python facebook-graph-api facebook-ads-api facebook-marketing-api facebook-python-business-sdk

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)

1 个答案:

答案 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纪元以来的秒数

希望获得帮助