How to get specific campaigns by name from Facebook Marketing API using Python?

Digital Marketing Facebook Marketing API 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I'm trying to get a list of specific ad campaigns by name from my Facebook business ad account using the Facebook Marketing API package in Python. I want to select only campaigns that match a certain name but I keep getting just a list of the 25 most recently created campaigns. How would I do this in Python? I haven't been able to find any examples for the right syntax for the "params" argument in the "get_campaigns" command. I would think that if I wanted to select just the campaigns named "Campaign-X" and "Campaign-Y" it might look something like this, if I could match 2 values to 1 key in a dictionary: from facebookads.api import FacebookAdsApi from facebookads.adobjects.campaign import Campaign app_id = 'xxxxx' app_secret = 'xxxxx' access_token = 'xxxxx' FacebookAdsApi.init(app_id, app_secret, access_token) account = AdAccount('act_xxxxxxxxx') account.get_campaigns(fields=[Campaign.Field.name], params={'name': ['Campaign-X', 'Campaign-Y']})

Posted on 16 Aug 2022, this text provides information on Facebook Marketing API related to Digital Marketing. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ You can try to use the filtering parameter to do this, which can do things like filtering results based on string matching: filtering=[{'field':'campaign.name','operator':'CONTAIN','value':'Campaign-x'}] However, I'm not sure it's possible to do OR operations with this so you'd need a pattern that matches all of the campaigns you need. The alternative is to do the filtering in code.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.