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

Digital Marketing Facebook Marketing API 3 years ago

5.66K 1 0 0 0

_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']})

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 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.
0 views
0 shares

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.

Similar Forum


Q

What are the best SEO tools for a personal website? What website or tools should I use to build and...

What are the best SEO tools for a personal website? What website or tools should I use to build and...
Q

Why is keyword research important?

Why is keyword research important?
Q

What is SEO ?

What is SEO ?