如何使用 Facebook 的 TargetingSearch API 进行复杂查询?

How to do complex queries using Facebook's TargetingSearch API?

我在此处找到了一些通过 Facebook api 进行目标搜索的不错的文档:

https://developers.facebook.com/docs/marketing-api/targeting-search/

我一直使用成功的代码,直接从上面的文档中复制过来的,如下:

(当然,这是在我设置了 Facebook API 身份验证之后。)

params = {
    'q': 'baseball',
    'type': 'adinterest',
}

resp = TargetingSearch.search(params=params)
print(resp) 

这很好用,returns 与棒球有关的主题列表,以及有关这些主题的信息,例如观众人数。

现在我真正想做的是执行更复杂的查询,例如:

return to me info on the audience of people who are in Santa Monica and who have an interest in baseball.

我想这样做是因为我希望能够看到该组的受众规模,但似乎无法找到有关如何执行此操作的文档或示例,或者是否可能。

我想象的是这样的:

params = {
    'q': 'baseball, santa_monica',
    'type': 'adinterest, adlocation',
}

resp = TargetingSearch.search(params=params)
print(resp)

但是上面的方法不行

非常感谢任何提示。

您要找的API叫Reachestimate。您可以使用您的目标来调用它,并将 return 预期数据。

例如,用作定位规范:

{
    "publisher_platforms": ["facebook"],
    "facebook_positions": ["feed", "right_hand_column"],
    "device_platforms": ["mobile", "desktop"],
    "geo_locations": {
        "countries": [],
        "custom_locations": [],
        "zips": [],
        "cities": [{
            "key": "2421905"
        }],
        "regions": [],
        "country_groups": [],
        "geo_markets": []
    },
    "excluded_geo_locations": {
        "countries": [],
        "custom_locations": [],
        "zips": [],
        "cities": [],
        "regions": [],
        "country_groups": [],
        "geo_markets": []
    },
    "genders": [1, 2],
    "age_min": 18,
    "age_max": 65,
    "relationship_statuses": [],
    "connections": [],
    "excluded_connections": [],
    "friends_of_connections": [],
    "interests": [{
        "id": "6003087413192",
        "name": "Baseball"
    }]
}

以下API呼叫:

curl -i -X GET \
 "https://graph.facebook.com/v3.2/act_XXX/reachestimate?targeting_spec=%7B%22publisher_platforms%22%3A%5B%22facebook%22%5D%2C%22facebook_positions%22%3A%5B%22feed%22%2C%22right_hand_column%22%5D%2C%22device_platforms%22%3A%5B%22mobile%22%2C%22desktop%22%5D%2C%22geo_locations%22%3A%7B%22countries%22%3A%5B%5D%2C%22custom_locations%22%3A%5B%5D%2C%22zips%22%3A%5B%5D%2C%22cities%22%3A%5B%7B%22key%22%3A%222421905%22%7D%5D%2C%22regions%22%3A%5B%5D%2C%22country_groups%22%3A%5B%5D%2C%22geo_markets%22%3A%5B%5D%7D%2C%22excluded_geo_locations%22%3A%7B%22countries%22%3A%5B%5D%2C%22custom_locations%22%3A%5B%5D%2C%22zips%22%3A%5B%5D%2C%22cities%22%3A%5B%5D%2C%22regions%22%3A%5B%5D%2C%22country_groups%22%3A%5B%5D%2C%22geo_markets%22%3A%5B%5D%7D%2C%22genders%22%3A%5B1%2C2%5D%2C%22age_min%22%3A18%2C%22age_max%22%3A65%2C%22relationship_statuses%22%3A%5B%5D%2C%22connections%22%3A%5B%5D%2C%22excluded_connections%22%3A%5B%5D%2C%22friends_of_connections%22%3A%5B%5D%2C%22interests%22%3A%5B%7B%22id%22%3A%226003087413192%22%2C%22name%22%3A%22Baseball%22%7D%5D%7D&access_token=<user_token>"

将return:

{
  "data": {
    "users": 12000,
    "estimate_ready": true
  }
}

希望对您有所帮助