Facebook广告API - 创建与广告管理器相似的效果报告
问题描述:
我目前使用Facebook SDK广告的Python SDK,主要用于在广告级自动生成基于效果的指标(例如展示次数,金额支出等)按月。根据documentation,似乎amount_spent仅在AdAccount级别,而我正在查找的大多数指标都不可用。Facebook广告API - 创建与广告管理器相似的效果报告
是否可以使用此API创建Ads Manager报告?如果我没有弄错,它应该是facebookads图书馆。
答
我认为你要找的是insights
。例如:
adcampaign = AdCampaign('<AD_CAMPAIGN_GROUP_ID>')
ads = adcampaign.get_ads(...)
for ad in ads:
insights = ad.get_insights(fields=['impressions', 'spend', ...])
我不使用此API或有权访问它,所以我无法测试它。这段代码是从查看文档和源代码。请让我知道这可不可以帮你。
相关链接:
- 的
Ad.get_insights()
function,我并没有真正看到它的文档,但它的源代码。 - Python SDK insights field names。
- 看起来像时间框架是一个参数
date_preset
。
答
这是我目前用来从Facebook营销api中获取洞察数据的代码。如果这是你正在寻找的东西。只需将您的表放置在foreach循环中,并在css文件中更改一些颜色,就可以获得与Facebook广告管理器类似的内容。
$account = new AdAccount('act_xxxxxxxxxxxxx');
$params = array(
'time_range' => array(
'since' => (new \DateTime($beginDate))->format('Y-m-d'),
'until' => (new \DateTime($lastDate))->format('Y-m-d'),
),
'level' => 'ad',
'limit' => '15'
);
$fields = array(
AdsInsightsFields::CAMPAIGN_NAME,
AdsInsightsFields::CAMPAIGN_ID,
AdsInsightsFields::IMPRESSIONS,
AdsInsightsFields::UNIQUE_CLICKS,
AdsInsightsFields::REACH,
AdsInsightsFields::SPEND,
AdsInsightsFields::TOTAL_ACTIONS,
);
$insights = $account->getInsights($fields, $params);
foreach($insights as $i){
$i->campaign_id;
etc.
etc.
}
感谢您的回复。我最终找到了我正在寻找的解决方案。正如Paco H.早些时候的回应:我不得不使用get_insights()函数来获得我需要的。 – wchang
没问题。很高兴你想出来了。 –