How to find ids of all existing Facebook ad campaigns

时间:2016-04-25 09:05:21

标签: python facebook-graph-api facebook-sdk-4.0 facebook-ads-api facebook-marketing-api

I want to extract ids of all ad campaigns using facebook api in python.

me = AdUser(fbid='me')
my_account = me.get_ad_account()

Now for AdAccount 'my_account', I want to get the list of ids of all campaigns. Tried to use

my_account.get_ad_campaigns() 

But it gives me the following error:

'AdAccount' object has no attribute 'get_ad_campaigns'

2 个答案:

答案 0 :(得分:2)

使用以下

%Userprofile%

答案 1 :(得分:1)

感谢Kanika,这对我帮助很大。

此外,为了获得id本身,您可以使用以下内容:

campaigns = account.get_campaigns()

camp_list = []

for campaign in campaigns:
    camp_list.append(campaign[Campaign.Field.id])

print(camp_list)

Facebook开发者似乎还没有完全更新他们的文档。您可以在此处查看回购信息以获取更多信息:

https://github.com/facebook/facebook-python-ads-sdk/tree/master/facebookads

请注意,根据Facebook,objects.py现已弃用:“请改用adobjects文件夹中的对象。”但是,看起来它们提供的一些代码片段仍然引用了objects.py。