預覽現有廣告並就您要建立的廣告產生預覽。產生的預覽以您的廣告創意為基礎。請為廣告預覽提供用戶存取憑證,而非專頁存取憑證。例如,預覽現有廣告創意的程式碼如下:
curl -X GET \
-d 'ad_format="DESKTOP_FEED_STANDARD"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0/<CREATIVE_ID>/previews
或者如果您使用外部網站的網域廣告之廣告創意規格來預覽廣告,程式碼則如下:
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
您可使用以下幾種方式產生預覽:
如要將使用現有廣告的廣告編號,請使用廣告的 previews
。
https://graph.facebook.com/<API_VERSION>/<AD_ID>/previews
如要使用現有廣告創意的編號,請使用廣告創意的 previews
。
https://graph.facebook.com/<API_VERSION>/<AD_CREATIVE_ID>/previews
您可透過兩個端點選項來使用廣告創意規格:
/generatepreviews
— 此呼叫中傳遞的廣告創意不應與特定廣告帳戶有所連結。對於進階高效速成目錄廣告,請將整個 object_story_spec 傳遞至 /generatepreviews 端點,同時請使用「進階高效速成目錄廣告:預覽」一文中所提到的 product_item_ids
。
只有在有關廣告帳戶中持有角色的用戶,才可檢視相應廣告帳戶中顯示的預覽。使用 generatepreviews
關係連線產生的預覽則可供所有人檢視。
https://graph.facebook.com/API_VERSION>/act_<AD_ACCOUNT_ID>/generatepreviews https://graph.facebook.com/API_VERSION>/generatepreviews
上述四個端點中的任何一個都將傳回廣告預覽物件
使用 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
使用 object_story_id
建立多商品廣告預覽。如要獲得 object_story_id
,請首先建立多商品廣告。
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
使用 object_story_spec
建立應用程式廣告預覽,這是為應用程式廣告產生預覽的唯一方式。
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_GRID_HOME 廣告格式的 Instagram「探索」主頁廣告預覽。
curl -X GET \
-d 'ad_format="INSTAGRAM_EXPLORE_GRID_HOME"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0
/<AD_ID>/previews
系統會傳回類似以下的內容:
{ "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_CHAIN 廣告格式的 Instagram 搜尋結果廣告預覽
curl -X GET \
-d 'ad_format="INSTAGRAM_SEARCH_CHAIN"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v21.0
/<AD_ID>/previews
系統會傳回類似以下的內容:
{ "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" }