我尝试将广告洞察与广告图片网址相关联,以便我可以在信息中心中展示广告及其效果。因此,我需要合并“广告见解”。带有广告图片的数据集'数据集。我知道如何单独拉它们,但不知道哪个列可以用作关键ID列来合并两个数据集。 (请注意,API中提供的字段比我下面使用的字段多得多。)
获取见解:
insights = account.get_insights(fields=[
AdsInsights.Field.date_start,
AdsInsights.Field.ad_id,
AdsInsights.Field.ad_name,
AdsInsights.Field.impressions,
AdsInsights.Field.clicks,
AdsInsights.Field.inline_post_engagement,
AdsInsights.Field.video_10_sec_watched_actions,
# AdsInsights.Field.canvas_avg_view_time,
], params={
'level': AdsInsights.Level.ad,
'breakdowns': 'publisher_platform',
'time_range': {'since': str(datetime.date(2017,1,15)), 'until': str(datetime.date(2017,1,21))},
})
广告洞察输出示例:
<AdsInsights> {
"ad_id": "6074251934453",
"ad_name": "Post 185|Campaign|Video|:15 Video|Chloe Ombre Legging|Womens|11.11|Gap|Holiday|Marcom|GapFit|On-figure",
"clicks": "80",
"date_start": "2017-01-15",
"date_stop": "2017-01-21",
"impressions": "29898",
"inline_post_engagement": "65",
"publisher_platform": "instagram",
"video_10_sec_watched_actions": [
{
"action_type": "video_view",
"value": "2342"
}
]
}
获取图片:
images = account.get_ad_images(fields=[
AdImage.Field.account_id,
AdImage.Field.created_time,
AdImage.Field.creatives,
AdImage.Field.permalink_url,
], params = {
'time_range': {'since': str(datetime.date(2017,1,15)), 'until': str(datetime.date(2017,1,21))}
})
广告图片输出示例:
<AdImage> {
"account_id": "104181146376574",
"created_time": "2017-03-08T10:45:57-0800",
"creatives": [
"6079059384653",
"6079059384853",
"6079059387253"
],
"id": "104181146376574:d2d60f26e67d99e6869c9b8444a3b30c",
"permalink_url": "https://www.facebook.com/ads/image/?d=AQIY0GjCTF9UUMExzqq2QAI3hFKgmObAyivAwfb346WgnzAIiysmGLjU_msd1pJcVxcr4zawWXHsiRviQjrW50lqTXxq3to6CQIQFLptp9DZ9Kanqx0tmFqoIB1_37PLqjGo7cK1bt6G2YxaL29ihdge"
}
&#39; ad_id&#39;和#39;广告素材&#39;在尝试合并它们之后看起来相似但没有匹配。
之前有过处理这个问题的经验吗?任何输入/想法将非常感激!
答案 0 :(得分:0)
广告图片应该被视为更像是一个图书馆&#39;以后可以使用的内容,请勿尝试将数据洞察与此相关联,因为可能会有使用特定图片的0或1个广告,或者不使用此库中图片的广告
用于您目的的数据模型可能应该是广告集 - &gt;广告 - &gt;广告创意
广告素材包含正在推广的内容的详细信息,通常是网页上的帖子,该帖子中有一个&#39;图片&#39;字段
答案 1 :(得分:0)
您可以通过以下方式执行此操作:
ad_id/insights
ad_id?fields=creative
creative_id?fields=image_url
我希望有所帮助!
答案 2 :(得分:0)
谢谢你们上面的回答;你指出了正确的方向。这是我对自己问题的解决方案,到目前为止一直很有效:
# get insights
insights = account.get_insights(fields=[
AdsInsights.Field.date_start,
AdsInsights.Field.ad_id,
AdsInsights.Field.ad_name,
AdsInsights.Field.impressions
], params={
'level': AdsInsights.Level.ad,
'time_range': {'since': str(datetime.date(2017, 3, 31)), 'until': str(datetime.date(2017, 3, 31))}
'time_increment': 1
})
# get a list of ad ids
insights_ids = [insight['ad_id'] for insight in insights]
url_list = []
count = 0
for ad_id in insights_ids:
ad = Ad(fbid=ad_id)
# get creative by ad_id
adcreatives = ad.get_ad_creatives(fields=[
AdCreative.Field.thumbnail_url,
AdCreative.Field.body
])
count += 1
print count
url_dict = {'ad_id': ad_id,
'thumbnail_url': adcreatives[0]['thumbnail_url']
}
url_list.append(url_dict)
time.sleep(2) # will likely hit rate limit when set to 1 sec
希望这可以帮助遇到同样问题的人!