对Facebook Marketing API进行多种过滤(日期范围,国家/地区,印象设备等)

时间:2018-12-18 08:40:05

标签: facebook-graph-api facebook-marketing-api facebook-insights

我们希望基于多种过滤条件(日期范围,国家/地区,印象设备等)从Facebook Marketing API(Insights API-https://developers.facebook.com/docs/marketing-api/insights)获取营销费用。

我一次可以应用1个过滤器,例如:

  • “国家/地区”:GET https://graph.facebook.com/v3.1/act_<ACCOUNT_ID>/insights?access_token=<ACCESS_TOKEN>&fields=["spend"]&time_range={"since":"YYYY-MM-DD","until":"YYYY-MM-DD"}&filtering=[{"field":"country","operator":"EQUAL","value":"GB"}]

  • “展示设备”:GET https://graph.facebook.com/v3.1/act_<ACCOUNT_ID>/insights?access_token=<ACCESS_TOKEN>&fields=["spend"]&time_range={"since":"YYYY-MM-DD","until":"YYYY-MM-DD"}&filtering=[{field:"impression_device","operator":"IN","value":["iphone","ipad"]}]

BUT不能在一个查询中同时使用这两个查询,而会得到下一个响应:

{
"error": {
    "message": "Service temporarily unavailable",
    "type": "OAuthException",
    "is_transient": false,
    "code": 2,
    "error_subcode": 1504018,
    "error_user_title": "Your request timed out",
    "error_user_msg": "Please try a smaller date range, fetch less data, or use async jobs",
    "fbtrace_id": "ADKphoammbM"
  }
}

我还尝试将报表作为异步作业运行(通过发出POST请求(如此处所述-https://developers.facebook.com/docs/marketing-api/insights/best-practices/#asynchronous),作业已成功启动:

{
"id": "317371612321115",
"account_id": "<ACCOUNT_ID>",
"time_ref": 1545121794,
"async_status": "Job Started",
"async_percent_completion": 0,
"is_running": true,
"date_start": "2018-12-17",
"date_stop": "2018-12-17"
}

但是随后出现“作业失败”状态:

{
"id": "317371612321115",
"account_id": "<ACCOUNT_ID>",
"time_ref": 1545121794,
"async_status": "Job Failed",
"async_percent_completion": 0,
"date_start": "2018-12-17",
"date_stop": "2018-12-17"
}

是否可以按照以下说明应用多个过滤器?
是否存在一些限制或文档如何应用多个过滤器?
谢谢。

1 个答案:

答案 0 :(得分:0)

您可以在同一请求中应用过滤器数组。试试:

filtering=[{field:"impression_device","operator":"IN","value":["iphone","ipad"]},{"field":"country","operator":"EQUAL","value":"GB"}]

这将返回以GB为单位的印象iPhone或iPad设备。