Chapter 45: Meta Ads Campaign Creation and Optimization Using Facebook Business, Graph, and Easy2Digital APIs

Along with user data privacy being cared for and protected more than ever, Meta has pledged to build an advertising ecosystem that relies on fewer data. It looks like the social media giant looks to push forward with its privacy agenda. Recently Meta has announced more removal of Facebook Ads audience targeting options across four categories. Plus the stress and impact from industrial players like iOS upgrade, I believe platform players just would have more new changes that create more challenges for marketers to reach out to customers accurately like before. 

However, the fact is platforms are shifting the data protection liability to the brands and marketers. For continuing monetizing the inventory without user privacy limitations, platforms are providing more mature marketing APIs for brands to adopt and leverage to reach out to target audiences even much better than before. And the brands and marketers build the target feature themselves at this time. This article is about how to leverage Meta APIs to create and update your Facebook, Instagram, Messenger, Whatsapp ads.

Along with user data privacy being cared for and protected more than ever, Meta has pledged to build an advertising ecosystem that relies on fewer data. It looks like the social media giant looks to push forward with its privacy agenda. Recently Meta has announced more removal of Facebook Ads audience targeting options across four categories. Plus the stress and impact from industrial players like iOS upgrade, I believe platform players just would have more new changes that create more challenges for marketers to reach out to customers accurately like before. 

However, the fact is platforms are shifting the data protection liability to the brands and marketers. For continuing monetizing the inventory without user privacy limitations, platforms are providing more mature marketing APIs for brands to adopt and leverage to reach out to target audiences even much better than before. And the brands and marketers build the target feature themselves at this time. This article is about how to leverage Meta APIs to create and update your Facebook, Instagram, Messenger, Whatsapp ads.

This is a new series of Python tutorials regarding marketing platform APIs to manage ads. I’ll release content from ads creation, ad automation, and customization to ads optimization. You can learn using Facebook business modules, and Graph API to create and update ads campaigns in this Meta ads ecosystem. They are Facebook, an audience network, Instagram, Whatsapp, and Messenger.

Python Modules and Tools: Facebook Business, Facebook Graph API

Type of social channel: Take Facebook for the example

Type of ads: Take video ads for the example

Table of Contents: Optimize Meta Ads Campaign Using Facebook Business, Graph, and Easy2Digital APIs

Meta Ads: Why Facebook Business Module and Graph API is the right way to go

There are three main reasons why the future is the marketing API world, which includes Meta ads.

User Data Privacy Restrict

User privacy and data protection have been in the spotlight and it doesn’t return back to the life we had before. In a way, it makes sense to protect users’ data. So from a platform perspective, less accurate targeting options and less precise tracking have become a fact. It’s because its data protection liability directly reflects on the features and functions given to brands and marketers.

Thus, platforms are providing opener and more mature marketing APIs to brands, which shifts the liability to brands making decisions on how to use and collect user data. Meanwhile, brands and markets can have a way to continue operating ads in an efficient approach.

Ads Automation

Tons of 3rd party advertising operation platforms out there provide digital ads automation. Basically, these platforms use marketing APIs to build easy-to-use SaaS platforms for marketers. The importance of ad automation is no doubt as more variables in the market impact the performance of the ads, so it needs more variant versions to engage with the audiences, by optimizing bidding, and ad creatives. And people need automated reporting to support making proper decisions. 

In this whole process, it’s basically impossible to manually manage because of workload and accuracy considerations.

Ads Customization

Meta ads ecosystem continues to narrow down the targeting options on the platform and it will continue of course. It means brands have more challenges with advertising ROI. But marketing API doesn’t have any limit on this aspect, it’s because brands lead and make decisions about where to collect user data, and what data to use. For example, you can integrate with the stock market pricing database to create dynamic customized ads based on a specific symbol pricing up or down. Or you can partner with clearbit to run lead generation campaigns in the Meta ads ecosystem like running ads on Linkedin.

Through marketing APIs, people can have a feeling of having more choices than just being sucked into the platform options.

Meta Ads – Facebook Business Module in Python

The Facebook business module provides plenty of parameters and methods to connect with Meta Graph API and interact with business managers and ad accounts. 

The module installation is straightforward and easy. In Macbook, we open the terminal and input the command pip3 install facebook-business with connecting the internet.

In the Python script, here is a list of modules we need to import:

from facebook_business.adobjects.adaccount import AdAccount

from facebook_business.adobjects.campaign import Campaign

from facebook_business.api import FacebookAdsApi

from facebook_business.adobjects.adset import AdSet

from facebook_business.adobjects.targetingsearch import TargetingSearch

from facebook_business.adobjects.targeting import Targeting

from facebook_business.adobjects.adimage import AdImage

from facebook_business.adobjects.adcreative import AdCreative

from facebook_business.adobjects.ad import Ad

Graph API credential: App ID, Page ID, Access_token, Ads account ID

First thing first, we need to create a Meta developer account and a new app in the Meta developer platform.

In the new app, we need to add the Facebook login and marketing API to the application. And please go to the basic setting on the left-hand side to check if you are using the latest API 13.0 version. Last but not least, please copy and paste the app ID, and put it in a place first. You will need it soon.

Then, we need to go to the tools on the top menu and click on Graph API explorer. In this section of the right-hand side, we select the Facebook app we just created above. And then it’s necessary to select which Facebook page you will use in the ads campaign. Here is a tip it’s best you use your ads account email address to sign up for the developer account. Thus, here it would give you the pages directly.

In the permission menu, we need to select all modules relevant to the ads and page management, which can facilitate us to build the application later on.

Now we can generate the access_token by clicking the blue button on the right-hand side. The token would be short-lived and would expire every 1 hour. So you can generate it when you like to activate your application.

Last but not least, we can generate the page id here as well inputting me?field=id in the bar on the top. Regarding the ads account ID, you can either output it here or copy the one in your ads account interface. But please remember to add act_ before the ads account ID

All in all, now you can create some variables and input relevant values before creating a campaign. For the campaign id, ads set id, creative id, and ads id, you would grab those later on.

  • access_token = ‘ ’
  • app_id =  '
  • id = ''
  • campaignId = ' '
  • adsSET_id = ' '
  • adsCreativeId = ' '
  • adsId = ' '

Authenticate the access to the token and state the API version

Before any coding, we need to authenticate our token to access the API and implement the activities we command. Here I will suggest adding the API version as well as the Facebook business module sometimes can’t detect which version you are using. This is a tiny step to avoid errors later on.

FacebookAdsApi.init(access_token=access_token, api_version='v13.0')

Campaign creation: objective

AI-driven is one of the most powerful ad features on Facebook. And selecting the campaign object in the first step is critical to start the ads in the right direction. For more details, please check out this article about sales vs click-driven campaigns.

Facebook Advertising Campaign – Sales vs Clicks Driven Campaign Objective Strategy

In the API section, there are 13 objective options and we have to select one as well as create a campaign in the Facebook ads manager. The default of the campaign objective is none.

CANVAS_APP_ENGAGEMENT

CANVAS_APP_INSTALLS

EVENT_RESPONSES

LOCAL_AWARENESS

MOBILE_APP_ENGAGEMENT

MOBILE_APP_INSTALLS

NONE (default)

OFFER_CLAIMS

PAGE_LIKES

POST_ENGAGEMENT

VIDEO_VIEWS

Then, we need to add the parameters and set up the campaign as we like. For the campaign creation statement and methods, it’s AdAccount().create_campaing(). For more parameters, we can use, please refer to the meta developer API documentation.

fields = [

]

params = {

  'name': 'python testing',

  'objective': 'LINK_CLICKS',

  'status': 'PAUSED',

  'special_ad_categories': [],

}

print(AdAccount(id).create_campaign(

  fields=fields,

  params=params,

))

Once you command these codes, you can get the campaign id and it’s for you to update, read and delete in the future. It’s very critical to implement automation and ad customization.

Ads set creation: bidding, targeting, optimization goal, and billing event

The ad set is a vital step as it deals with bidding strategy, media buy approach, customer data, targeting, GEO, budget, etc.

In the parameters, we need to add campaign_id and access_token, as we need to tell the API which campaign this ad set would be added on. For the ad set statement and method, we can use AdAccount().create_ad_set()

For more parameter information, please refer to the meta developer API documentation. Once you command these codes, you can get the ad set id

Take video ads for example in ad creative creation

In the ads creative section, you can code to create the type of ads, input the ads materials and select the ads placement based on the type of ads you are going to run.

Basically, there are 11 ad options you can select, which are single image ads, post ads, page-like ads, story ads, slideshow ads, app ads, carousel ads, dynamic ads, Instagram ads, leads ads, and videos.

For Facebook’s dynamic ads strategy, please check out this article for more details.

Facebook Ads: How to Optimise Dynamic Product Ads for Sales & Revenue

Apart from the parameters of the ad to set up your ads and access token, you can need to add the ad set id and page id to tell. It tells which page you will use to run ads and which ad set the creative would be added on.

For the video ads element settings, we need to add the thumbnail image, description, videos, call-to-action, message, etc. For more parameter details, please refer to the meta developer API documentation.

Creating an ad creative is not done yet, because Facebook puts it as a mission complete on the creative message and placement confirmation. We need to create the ads using the other set of codings.

Update campaign, ad set, and ads

Creating is the earliest stage of using meta APIs, as the most beautiful thing about using API is to operate and optimize. I’ll release other articles to share different approaches. Here today is to share how to update a single campaign, ad set, and ads. Once you pick up the logic, it’s very easier to update batches you would learn from my articles in the future.

In the update section, the method is api_update(), which is different from the creation stage method.

Full Python Script of Using Facebook Business and Graph API to Create Ads Campaigns

If you are interested in the full Python script of Chapter 45: Meta Ads Campaign Creation and Optimization Using Facebook Business, Graph, and Easy2Digital APIs, please subscribe to our newsletter by adding the message “Chapter 45”. We would send you the script immediately to your mailbox.

I hope you enjoy reading Chapter 45: Meta Ads Campaign Creation and Optimization Using Facebook Business, Graph, and Easy2Digital APIs. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

  • Support and donate to our channel through PayPal (paypal.me/Easy2digital)
  • Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
  • Follow and like my page Easy2Digital Facebook page
  • Share the article on your social network with the hashtag #easy2digital
  • Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
  • You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount codes on Buyfromlo products and digital software
  • Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)

FAQ:

Q1: What is Meta Ads Campaign API?

A: Meta Ads Campaign API is a brand product offered by Meta Ads, which is an advertising platform that allows businesses to create, manage, and optimize their advertising campaigns across various channels.

Q2: How can Meta Ads Campaign API benefit my eCommerce business?

A: Meta Ads Campaign API can benefit your eCommerce business by providing a seamless integration with your existing systems, allowing you to automate campaign creation, optimize ad targeting, and track performance metrics in real-time.

Q3: Can I use Meta Ads Campaign API with any eCommerce platform?

A: Yes, Meta Ads Campaign API is designed to be platform-agnostic and can be integrated with any eCommerce platform that supports API connectivity.

Q4: What features does Meta Ads Campaign API offer?

A: Meta Ads Campaign API offers a range of features including campaign creation, ad targeting, budget management, performance tracking, and reporting analytics.

Q5: How can I get started with Meta Ads Campaign API?

A: To get started with Meta Ads Campaign API, you will need to sign up for an account on the Meta Ads platform and obtain API credentials. Once you have the credentials, you can integrate the API with your eCommerce platform.

Q6: Does Meta Ads Campaign API support multi-channel advertising?

A: Yes, Meta Ads Campaign API supports multi-channel advertising, allowing you to create and manage campaigns across various channels such as search engines, social media platforms, and display networks.

Q7: Can I customize the ad targeting options with Meta Ads Campaign API?

A: Yes, Meta Ads Campaign API provides flexible ad targeting options, allowing you to define specific demographics, interests, and behaviors to reach your target audience effectively.

Q8: Does Meta Ads Campaign API provide real-time performance tracking?

A: Yes, Meta Ads Campaign API provides real-time performance tracking, allowing you to monitor key metrics such as impressions, clicks, conversions, and ROI.

Q9: Is there a limit to the number of campaigns I can create with Meta Ads Campaign API?

A: There is no specific limit to the number of campaigns you can create with Meta Ads Campaign API. You can create and manage as many campaigns as your business requires.

Q10: What level of technical expertise is required to use Meta Ads Campaign API?

A: While some technical knowledge is beneficial, Meta Ads Campaign API is designed to be user-friendly and accessible to users with varying levels of technical expertise. The Meta Ads documentation provides detailed guides and examples to help you integrate and utilize the API effectively.

Meta API Endpoint Recommendation

AI Product Ads & SEO Metatag Content Generator API

Price: US$19

Generate AI product digital ads and seo metatag content using product name and raw content. It automatically returns the article content generated by Easy2Digital AI integrated system which integrates with multi LLM modules (Vertex, Llama, Claude, GPT3.5, GPT3, GPT-J, GPT NEOX, etc). Digital ads include SEM, social media, native, display text, video text part, etc. Paid API token can access to BuyfromLo onsite app, meanwhile API returns image bytecode in JSON form.

More API options from the Meta collection. 

SAVE UP TO 50% and EXPLORE MORE!