我在这里找到了一些不错的文档,用于通过Facebooks api进行定位搜索:
https://developers.facebook.com/docs/marketing-api/targeting-search/
我一直在成功使用的代码直接从上述文档中复制而成,如下所示:
(当然,这是在我使用Facebook API设置了身份验证之后。)
params = {
'q': 'baseball',
'type': 'adinterest',
}
resp = TargetingSearch.search(params=params)
print(resp)
效果很好,并返回与棒球相关的主题列表,以及有关这些主题的信息,例如观众人数。
现在,我真正想要做的是执行一个更复杂的查询,如下所示:
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。您可以使用自己的定位条件调用它,并返回预期的数据。
作为示例,使用作为定位规范:
{
"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>"
将返回:
{
"data": {
"users": 12000,
"estimate_ready": true
}
}
希望有帮助
Python uuid4,如何限制唯一字符的长度 - python在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…
Python-crontab模块 - python我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…
Python:检查是否存在维基百科文章 - python我试图弄清楚如何检查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不会,页面只是说:“维基百科没有此名称的文章。”谢谢! 参考方案 >>> import urllib >>> prin…
Python Pandas导出数据 - python我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…
Python:在不更改段落顺序的情况下在文件的每个段落中反向单词? - python我想通过反转text_in.txt文件中的单词来生成text_out.txt文件,如下所示:text_in.txt具有两段,如下所示:Hello world, I am Here. I am eighteen years old. text_out.txt应该是这样的:Here. am I world, Hello old. years eighteen a…