Use Facebook ads with your existing customers and to reach new ones. Each guide describes Facebook ads products to help meet your advertising goals. There are several types of ad units with a variety of appearances, placement and creative options. For guidelines on ads units as creative content, see Facebook Ads Guide.
An ad creative is an object that contains all the data for visually rendering the ad itself. In the API, there are different types of ads that you can create on Facebook, all listed here.
If you have a campaign with the Page Post Engagement Objective, you can now create an ad that promotes a post made by the page. This is considered a Page post ad. Page post ads require a field called object_story_id
, which is the id
property of a Page post. Learn more about Ad Creative, Reference.
An ad creative has three parts:
To create the ad creative object, make the following call:
The response to the API call is the id
of the creative object. Store this; you need it for the ad object:
There are limits on the creative's text, image size, image aspect ratio and other aspects of the creative. See the Ads Guide.
In the Ads API, each field you want to retrieve needs to be asked for explicitly, except for id
. Each object's Reference has a section for reading back the object and lists what fields are readable. For the creative, it's the same fields as specified when creating the object, and id
.
A placement is where your ad is shown on Facebook, such as on Feed on desktop, Feed on a mobile device or on the right column. See Ads Product Guide.
We encourage you to run ads across the full range of available placements. Facebook’s ad auction is designed to deliver ad impressions to the placement most likely to drive campaign results at the lowest possible cost.
The easiest way to take advantage of this optimization is to leave this field blank. You can also select specific placements in an ad set’s target_spec.
This example has a page post ad. The available placements are Mobile Feed, Desktop Feed and Right column of Facebook. In the API, see Placement Options. If you choose desktopfeed
and rightcolumn
as the page_type
, the ad runs on Desktop Feed and Right column placements. Any ad created below this ad set has only the desktop placement.
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
AdSetFields::NAME => 'Desktop Ad Set',
AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
AdSetFields::DAILY_BUDGET => 10000,
AdSetFields::TARGETING => (new Targeting())->setData(array(
TargetingFields::PUBLISHER_PLATFORMS => array(
'facebook',
'audience_network',
),
TargetingFields::GEO_LOCATIONS => array(
'countries' => array('BR'),
),
)),
AdSetFields::OPTIMIZATION_GOAL =>
AdSetOptimizationGoalValues::POST_ENGAGEMENT,
AdSetFields::BILLING_EVENT => AdSetBillingEventValues::POST_ENGAGEMENT,
AdSetFields::BID_AMOUNT => 1500,
));
$adset->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting
adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset[AdSet.Field.name] = 'Desktop Ad Set'
adset[AdSet.Field.campaign_id] = <CAMPAIGN_ID>
adset[AdSet.Field.daily_budget] = 10000
adset[AdSet.Field.targeting] = {
Targeting.Field.publisher_platforms: ['facebook', 'audience_network'],
Targeting.Field.facebook_positions: ['feed'],
Targeting.Field.geo_locations: {
'countries': ['BR'],
},
}
adset[AdSet.Field.optimization_goal] = AdSet.OptimizationGoal.post_engagement
adset[AdSet.Field.billing_event] = AdSet.BillingEvent.post_engagement
adset[AdSet.Field.bid_amount] = 1500
adset.remote_create(params={
'status': AdSet.Status.paused,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
.setName("Desktop Ad Set")
.setCampaignId(<CAMPAIGN_ID>)
.setDailyBudget(10000L)
.setTargeting(
new Targeting()
.setFieldGeoLocations(
new TargetingGeoLocation()
.setFieldCountries(Arrays.asList("BR"))
)
.setFieldPublisherPlatforms(Arrays.asList("facebook", "audience_network"))
)
.setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_POST_ENGAGEMENT)
.setBillingEvent(AdSet.EnumBillingEvent.VALUE_POST_ENGAGEMENT)
.setBidAmount(1500L)
.setStatus(AdSet.EnumStatus.VALUE_PAUSED)
.execute();
String ad_set_id = adSet.getId();
curl \
-F 'name=Desktop Ad Set' \
-F 'campaign_id=<CAMPAIGN_ID>' \
-F 'daily_budget=10000' \
-F 'targeting={
"geo_locations": {"countries":["BR"]},
"publisher_platforms": ["facebook","audience_network"]
}' \
-F 'optimization_goal=POST_ENGAGEMENT' \
-F 'billing_event=POST_ENGAGEMENT' \
-F 'bid_amount=1500' \
-F 'status=PAUSED' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/adsets
You preview an ad in one of two ways—with ad preview API or the ad preview plugin.
There are three ways to generate a preview with the API:
Following the reference docs for the preview API, the minimum required API call is:
The creative spec is an array of each field and value required to create the ad creative.
Currently, our ad creative call looks like this:
Take object_story_id
and use it in the preview API call:
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Fields\AdCreativeFields;
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->getGeneratePreviews(array(), array(
AdPreviewFields::CREATIVE => array(
AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
),
AdPreviewFields::AD_FORMAT => '<FORMAT>',
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adcreative import AdCreative
account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
'creative': {
AdCreative.Field.object_story_id: '<POST_ID>',
},
'ad_format': '<FORMAT>',
}
account.get_generate_previews(params=params)
APINodeList<AdPreview> adPreviews = new AdAccount(act_<AD_ACCOUNT_ID>, context).getGeneratePreviews()
.setCreative(
new AdCreative()
.setFieldObjectStoryId(<OBJECT_STORY_ID>)
)
.setAdFormat(<FORMAT>)
.execute();
curl -G \
-d 'creative={"object_story_id":"<POST_ID>"}' \
-d 'ad_format=<FORMAT>' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews
The available values for ad_format
differ a bit from page_types
. But, in this scenario, Desktop Feed and Right column of Facebook are selected. This requires you to make two API calls to generate the previews for each placement:
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Values\AdPreviewAdFormatValues;
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->getGeneratePreviews(array(), array(
AdPreviewFields::CREATIVE => array(
AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
),
AdPreviewFields::AD_FORMAT => AdPreviewAdFormatValues::RIGHT_COLUMN_STANDARD,
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adpreview import AdPreview
from facebookads.adobjects.adcreative import AdCreative
account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
'creative': {
AdCreative.Field.object_story_id: '<POST_ID>',
},
'ad_format': AdPreview.AdFormat.right_column_standard,
}
account.get_generate_previews(params=params)
APINodeList<AdPreview> adPreviews = new AdAccount(act_<AD_ACCOUNT_ID>, context).getGeneratePreviews()
.setCreative(
new AdCreative()
.setFieldObjectStoryId(<OBJECT_STORY_ID>)
)
.setAdFormat(AdPreview.EnumAdFormat.VALUE_RIGHT_COLUMN_STANDARD)
.execute();
curl -G \
-d 'creative={"object_story_id":"<POST_ID>"}' \
-d 'ad_format=RIGHT_COLUMN_STANDARD' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews
The response is an iFrame that's valid for 24 hrs.