Preview existing ads and generate previews of ads you want to create. Generated previews are based on your ad creative. For ad preview provide a user access token, not a Page access token. For example, preview existing ad creative:
curl -X GET \
-d 'ad_format="DESKTOP_FEED_STANDARD"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0/<CREATIVE_ID>/previews
Or preview using creative spec for a domain ad for an external website:
curl -X GET \
-d 'creative="<CREATIVE_SPEC>"' \
-d 'ad_format="<AD_FORMAT>"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/generatepreviews
There are a few ways to generate a preview, using:
To use an ad ID for an existing ad, use ad's previews
.
https://graph.facebook.com/<API_VERSION>/<AD_ID>/previews
To use an existing ad creative's ID, use the ad creative's previews
.
https://graph.facebook.com/<API_VERSION>/<AD_CREATIVE_ID>/previews
To use an ad creative spec, you have two endpoint options:
/act_<AD_ACCOUNT_ID>/generatepreviews
, or/generatepreviews
— The creative passed in this call should not be associated with a specific ad account.For Advantage+ catalog ads pass the entire object_story_spec into the /generatepreviews endpoint, and also use product_item_ids
described in Advantage+ Catalog Ads, Preview.
Previews from an ad account are only visible to people who have a role on the ad account. Previews generated using generatepreviews
edge are visible to anyone.
https://graph.facebook.com/API_VERSION>/act_<AD_ACCOUNT_ID>/generatepreviews https://graph.facebook.com/API_VERSION>/generatepreviews
Any of the four endpoints above will return an ad preview object
Create a preview using object_story_spec
:
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Values\AdPreviewAdFormatValues;
use FacebookAds\Object\Values\AdCreativeCallToActionTypeValues;
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::LINK => '<URL>',
AdCreativeLinkDataFields::MESSAGE => 'Message',
AdCreativeLinkDataFields::NAME => 'Name',
AdCreativeLinkDataFields::DESCRIPTION => 'Description',
AdCreativeLinkDataFields::CALL_TO_ACTION => array(
'type' => AdCreativeCallToActionTypeValues::SIGN_UP,
'value' => array(
'link' => '<URL>',
),
),
));
$story = new AdCreativeObjectStorySpec();
$story->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));
$creative = new AdCreative();
$creative->setData(array(
AdCreativeFields::OBJECT_STORY_SPEC => $story,
));
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->getGeneratePreviews(array(), array(
AdPreviewFields::CREATIVE => $creative,
AdPreviewFields::AD_FORMAT => AdPreviewAdFormatValues::DESKTOP_FEED_STANDARD,
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adpreview import AdPreview
from facebookads.adobjects.adcreative import AdCreative
from facebookads.adobjects.adcreativelinkdata import AdCreativeLinkData
from facebookads.adobjects.adcreativeobjectstoryspec \
import AdCreativeObjectStorySpec
link_data = AdCreativeLinkData()
link_data.update({
AdCreativeLinkData.Field.link: url,
AdCreativeLinkData.Field.message: "Message",
AdCreativeLinkData.Field.name: "Name",
AdCreativeLinkData.Field.description: "Description",
AdCreativeLinkData.Field.call_to_action: {
"type": "SIGN_UP",
"value": {
"link": url,
"link_caption": "CTA caption",
},
},
})
story = AdCreativeObjectStorySpec()
story.update({
AdCreativeObjectStorySpec.Field.link_data: link_data,
AdCreativeObjectStorySpec.Field.page_id: '<PAGE_ID>',
})
creative = AdCreative()
creative.update({
AdCreative.Field.object_story_spec: story,
})
account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
'ad_format': AdPreview.AdFormat.desktop_feed_standard,
'creative': creative.export_data(),
}
ad_preview = account.get_generate_previews(params=params)
print(ad_preview)
APINodeList<AdPreview> adPreviews = new AdAccount(act_<AD_ACCOUNT_ID>, context).getGeneratePreviews()
.setCreative(
new AdCreative()
.setFieldObjectStorySpec(
new AdCreativeObjectStorySpec()
.setFieldLinkData(
new AdCreativeLinkData()
.setFieldCallToAction(
new AdCreativeLinkDataCallToAction()
.setFieldType(AdCreativeLinkDataCallToAction.EnumType.VALUE_SIGN_UP)
.setFieldValue(
new AdCreativeLinkDataCallToActionValue()
.setFieldLink(<URL>)
.setFieldLinkCaption("CTA Caption")
)
)
.setFieldDescription("Description")
.setFieldLink(<URL>)
.setFieldMessage("Message")
.setFieldName("Name")
)
.setFieldPageId(<PAGE_ID>)
)
)
.setAdFormat(AdPreview.EnumAdFormat.VALUE_DESKTOP_FEED_STANDARD)
.execute();
curl -G \
--data-urlencode 'creative={
"object_story_spec": {
"link_data": {
"call_to_action": {"type":"SIGN_UP","value":{"link":"<URL>"}},
"description": "Description",
"link": "<URL>",
"message": "Message",
"name": "Name"
},
"page_id": "<PAGE_ID>"
}
}' \
-d 'ad_format=DESKTOP_FEED_STANDARD' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews
Create an multi-product ad preview using object_story_id
. To get object_story_id
, first create a Multi-Product Ad.
curl -X GET \
-d 'creative={
"object_story_id": "<PAGE_ID>_<POST_ID>"
}' \
-d 'ad_format="DESKTOP_FEED_STANDARD"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/generatepreviews
Create an app ad preview using object_story_spec
. This is the only way to generate a preview for an app ad.
curl -X GET \
-d 'creative={
"object_story_spec": {
"link_data": {
"call_to_action": {
"type": "USE_APP",
"value": {
"link": "<URL>"
}
},
"description": "Description",
"link": "<URL>",
"message": "Message",
"name": "Name",
"picture": "<IMAGE_URL>"
},
"page_id": "<PAGE_ID>"
}
}' \
-d 'ad_format="MOBILE_FEED_STANDARD"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0/act_<AD_ACCOUNT_ID>/generatepreviews
Instagram Explore home Ad Previews using INSTAGRAM_EXPLORE_GRID_HOME ad format
curl -X GET \
-d 'ad_format="INSTAGRAM_EXPLORE_GRID_HOME"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0
/<AD_ID>/previews
This returns something like this:
{ "data": [ { "body": "<iframe src=\"https://www.facebook.com/ads/api/preview_iframe.php?d=AQKuwYcWpyFgVKLORPWQi52_uTud4v8PpMoDtyBfntL65i0iFtgkiXWN5S4JMBhq-UMKQmvxXFexVxu-5l5Xbf4WWRP48sCAtn3ArQAXwbdrD5qH0EL2z34K-gAgYyENd80cOGAdhVreKGJZvPkLbjDS3iDkdqdNNJQ6yaAFTmUpaz__cjgmhVVCUW68wU3UOZwqlv376mkijYR57Sm2OlyES4U6ivMPNGDx4xnZEd5d8kWyagDD-lPbCaGEk0nnQF5mnyeV9pFqdByhq-IqN6n0ZhSWjCPXZQa84wu5GNQ70YR2w7QxEYoiWCgI2WP0Z2OPeUMiNOf9bhYB-TBZJZ7G6HylsOnzzII9FQ8-0K-b_Q&t=AQJws9t-TtIGrKoFtCM\" width=\"274\" height=\"213\" scrolling=\"yes\" style=\"border: none;\"></iframe>" } ] }
Instagram search results Ad Previews using INSTAGRAM_SEARCH_CHAIN ad format
curl -X GET \
-d 'ad_format="INSTAGRAM_SEARCH_CHAIN"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0
/<AD_ID>/previews
This returns something like this:
{ "data": [ { "body": "<iframe src=\"https://www.facebook.com/ads/api/preview_iframe.php?d=AQKVMPdwuorP3mliXRaOi0TCSvsGRfucEzBTnB4jghArle84f8kBjvJmX3gmdjniUjohKA3GUppDZqljStZwxxRRxkQl9Y4R1o5wV4zRGE3xO3NHf1_qBbFM_uEIGAnAvptMWo_DLpbiIqIYFMjxbXNELzmZQsR0gnbBjaXM9i6gkI29dnHPqnm4xGvPxo2w8RWeXfWvmik2C96_2PrhrRhh4NKL3SOmFC9JDVsTp9Z6SYDlLVcLJWwpRKmciAZqEMOnMEFgepVTZ39yJ4ZiAMRo76RK9XNVGcornsUBtxI8cZHKtdW7nmj3ivq09_NGGUnFiJdJaPm-Mk-obM3K0QyOvgHKwnmLn7wvMiizJeXPEWAcSBa4DPUFLAO1mSuaKla0VQ6tzAM4BqFU9LJOG1-zZmPec7wKxQGDcrXoCOKfv2xkLyzECc-oDS0JJgvxxlo&t=AQI8ECKvkemIoVDaDrs\" width=\"274\" height=\"213\" scrolling=\"yes\" style=\"border: none;\"></iframe>" } ], "__www_request_id__": "AzCC2RoeSL0rMbSPTYDyDHa" }