Creative, Placement, and Preview

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.

Creative

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:

  • Ad creative itself, defined by the visual attributes of the creative object
  • Placement that the ad runs on
  • Preview of the unit itself, per placement

To create the ad creative object, make the following call:

curl -X POST \ -F 'name=Sample Promoted Post' \ -F 'object_story_id=<PAGE_ID>_<POST_ID>' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v3.0/act_<AD_ACCOUNT_ID>/adcreatives
const adsSdk = require('facebook-nodejs-ads-sdk'); const AdAccount = adsSdk.AdAccount; const AdCreative = adsSdk.AdCreative; let access_token = '<ACCESS_TOKEN>'; let app_secret = '<APP_SECRET>'; let app_id = '<APP_ID>'; let id = '<ID>'; const api = adsSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const fields = [ ]; const params = { 'name' : 'Sample Promoted Post', 'object_story_id' : '<pageID>_<postID>', }; (new AdAccount(id)).createAdCreative( fields, params ) .then((result) => { adcreatives_id = result.id; console.log(adcreatives_id); }) .catch((error) => { console.log(error); });
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdCreative; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'Sample Promoted Post', 'object_story_id' => '<pageID>_<postID>', ); echo json_encode((new AdAccount($id))->createAdCreative( $fields, $params )->getResponse()->getContent(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount from facebookads.adobjects.adcreative import AdCreative from facebookads.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'Sample Promoted Post', 'object_story_id': '<pageID>_<postID>', } print AdAccount(id).create_ad_creative( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdCreative() .setName(\"Sample Promoted Post\") .setObjectStoryId(\"<pageID>_<postID>\") .execute(); } }
access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) ad_account.adcreatives.create({ name: 'Sample Promoted Post', object_story_id: '<pageID>_<postID>', })

The response to the API call is the id of the creative object. Store this; you need it for the ad object:

curl -X POST \ -F 'name=My Ad' \ -F 'adset_id=<AD_SET_ID>' \ -F 'creative={"creative_id":"<CREATIVE_ID>"}' \ -F 'status=PAUSED' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v3.0/act_<AD_ACCOUNT_ID>/ads
const adsSdk = require('facebook-nodejs-ads-sdk'); const AdAccount = adsSdk.AdAccount; const Ad = adsSdk.Ad; let access_token = '<ACCESS_TOKEN>'; let app_secret = '<APP_SECRET>'; let app_id = '<APP_ID>'; let id = '<ID>'; const api = adsSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const fields = [ ]; const params = { 'name' : 'My Ad', 'adset_id' : '<adSetID>', 'creative' : {'creative_id':'<adCreativeID>'}, 'status' : 'PAUSED', }; (new AdAccount(id)).createAd( fields, params ) .then((result) => { ads_id = result.id; console.log(ads_id); }) .catch((error) => { console.log(error); });
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\Ad; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'My Ad', 'adset_id' => '<adSetID>', 'creative' => array('creative_id' => '<adCreativeID>'), 'status' => 'PAUSED', ); echo json_encode((new AdAccount($id))->createAd( $fields, $params )->getResponse()->getContent(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount from facebookads.adobjects.ad import Ad from facebookads.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'My Ad', 'adset_id': '<adSetID>', 'creative': {'creative_id':'<adCreativeID>'}, 'status': 'PAUSED', } print AdAccount(id).create_ad( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAd() .setName(\"My Ad\") .setAdsetId(<adSetID>L) .setCreative( new AdCreative() .setFieldId(\"<adCreativeID>\") ) .setStatus(Ad.EnumStatus.VALUE_PAUSED) .execute(); } }
access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) ad_account.ads.create({ name: 'My Ad', adset_id: '<adSetID>', creative: {'creative_id':'<adCreativeID>'}, status: 'PAUSED', })

Creative Limits

There are limits on the creative's text, image size, image aspect ratio and other aspects of the creative. See the Ads Guide.

Read

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:

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;

$creative = new AdCreative(<CREATIVE_ID>);
$creative->read(array(
  AdCreativeFields::NAME,
  AdCreativeFields::OBJECT_STORY_ID,
));
from facebookads.adobjects.adcreative import AdCreative

creative = AdCreative(<CREATIVE_ID>)
creative.remote_read(
    fields=[AdCreative.Field.name, AdCreative.Field.object_story_id]
)
AdCreative adCreative2 = new AdCreative(<CREATIVE_ID>, context).get()
  .requestNameField()
  .requestObjectStoryIdField()
  .execute();
curl -G \
  -d 'fields=name,object_story_id' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/<CREATIVE_ID>

Placements

A placement is where your ad is shown on Facebook, such as on News Feed on desktop, News Feed on a mobile device or on the right column. See Ads Product Guide.

This example has a page post ad. The available placements are Mobile News Feed, Desktop News 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 News 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

Preview an Ad

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:

  1. By ad ID
  2. By ad creative ID
  3. By supplying a creative spec

Following the reference docs for the preview API, the minimum required API call is:

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdPreviewFields;

$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->getGeneratePreviews(array(), array(
  AdPreviewFields::CREATIVE => <CREATIVE_SPEC>,
  AdPreviewFields::AD_FORMAT => '<FORMAT>',
));
from facebookads.adobjects.adaccount import AdAccount

account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
    'creative': <CREATIVE_SPEC>,
    'ad_format': '<FORMAT>',
}
account.get_generate_previews(params=params)
APINodeList<AdPreview> adPreviews = new AdAccount(act_<AD_ACCOUNT_ID>, context).getGeneratePreviews()
  .setCreative(<CREATIVE_SPEC>)
  .setAdFormat(<FORMAT>)
  .execute();
curl -G \
  -d 'creative=<CREATIVE_SPEC>' \
  -d 'ad_format=<FORMAT>' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews

The creative spec is an array of each field and value required to create the ad creative.

Currently, our ad creative call looks like:

curl -X POST \ -F 'name=Sample Promoted Post' \ -F 'object_story_id=<PAGE_ID>_<POST_ID>' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v3.0/act_<AD_ACCOUNT_ID>/adcreatives
const adsSdk = require('facebook-nodejs-ads-sdk'); const AdAccount = adsSdk.AdAccount; const AdCreative = adsSdk.AdCreative; let access_token = '<ACCESS_TOKEN>'; let app_secret = '<APP_SECRET>'; let app_id = '<APP_ID>'; let id = '<ID>'; const api = adsSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const fields = [ ]; const params = { 'name' : 'Sample Promoted Post', 'object_story_id' : '<pageID>_<postID>', }; (new AdAccount(id)).createAdCreative( fields, params ) .then((result) => { adcreatives_id = result.id; console.log(adcreatives_id); }) .catch((error) => { console.log(error); });
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdCreative; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'Sample Promoted Post', 'object_story_id' => '<pageID>_<postID>', ); echo json_encode((new AdAccount($id))->createAdCreative( $fields, $params )->getResponse()->getContent(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount from facebookads.adobjects.adcreative import AdCreative from facebookads.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'Sample Promoted Post', 'object_story_id': '<pageID>_<postID>', } print AdAccount(id).create_ad_creative( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdCreative() .setName(\"Sample Promoted Post\") .setObjectStoryId(\"<pageID>_<postID>\") .execute(); } }
access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) ad_account.adcreatives.create({ name: 'Sample Promoted Post', object_story_id: '<pageID>_<postID>', })

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 News 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::DESKTOP_FEED_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.desktop_feed_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_DESKTOP_FEED_STANDARD)
  .execute();
curl -G \
  -d 'creative={"object_story_id":"<POST_ID>"}' \
  -d 'ad_format=DESKTOP_FEED_STANDARD' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/generatepreviews
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.

Copy Ads

You can also copy an existing ad, asset or campaign. It helps you quickly duplicate a campaign to change configurations or create test groups to extract performance knowledge. For more details, see:

Creating Page Like Ads

In July 2018 we will deprecate the ability to create a Page Like ad without a page post. If you want to create this type of ad you should specifically create a post. For example:

curl -X POST \ -F 'name=Creative' \ -F 'object_story_spec={"page_id":"<PAGE_ID>","link_data":{"image_hash":"<IMAGE_HASH>","link":"https:\/\/facebook.com\/<PAGE_ID>","message":"Creative message","call_to_action":{"type":"LIKE_PAGE","value":{"page":"<PAGE_ID>"}}}}' \ -F 'access_token=<ACCESS_TOKEN>' \ https://graph.facebook.com/v3.0/act_<AD_ACCOUNT_ID>/adcreatives
const adsSdk = require('facebook-nodejs-ads-sdk'); const AdAccount = adsSdk.AdAccount; const AdCreative = adsSdk.AdCreative; let access_token = '<ACCESS_TOKEN>'; let app_secret = '<APP_SECRET>'; let app_id = '<APP_ID>'; let id = '<ID>'; const api = adsSdk.FacebookAdsApi.init(access_token); const showDebugingInfo = true; // Setting this to true shows more debugging info. if (showDebugingInfo) { api.setDebug(true); } const fields = [ ]; const params = { 'name' : 'Creative', 'object_story_spec' : {'page_id':'<pageID>','link_data':{'image_hash':'<imageHash>','link':'https:\/\/facebook.com\/<pageID>','message':'Creative message','call_to_action':{'type':'LIKE_PAGE','value':{'page':'<pageID>'}}}}, }; (new AdAccount(id)).createAdCreative( fields, params ) .then((result) => { adcreatives_id = result.id; console.log(adcreatives_id); }) .catch((error) => { console.log(error); });
require __DIR__ . '/vendor/autoload.php'; use FacebookAds\Object\AdAccount; use FacebookAds\Object\AdCreative; use FacebookAds\Api; use FacebookAds\Logger\CurlLogger; $access_token = '<ACCESS_TOKEN>'; $app_secret = '<APP_SECRET>'; $app_id = '<APP_ID>'; $id = '<ID>'; $api = Api::init($app_id, $app_secret, $access_token); $api->setLogger(new CurlLogger()); $fields = array( ); $params = array( 'name' => 'Creative', 'object_story_spec' => array('page_id' => '<pageID>','link_data' => array('image_hash' => '<imageHash>','link' => 'https:\/\/facebook.com\/<pageID>','message' => 'Creative message','call_to_action' => array('type' => 'LIKE_PAGE','value' => array('page' => '<pageID>')))), ); echo json_encode((new AdAccount($id))->createAdCreative( $fields, $params )->getResponse()->getContent(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount from facebookads.adobjects.adcreative import AdCreative from facebookads.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAdsApi.init(access_token=access_token) fields = [ ] params = { 'name': 'Creative', 'object_story_spec': {'page_id':'<pageID>','link_data':{'image_hash':'<imageHash>','link':'https:\/\/facebook.com\/<pageID>','message':'Creative message','call_to_action':{'type':'LIKE_PAGE','value':{'page':'<pageID>'}}}}, } print AdAccount(id).create_ad_creative( fields=fields, params=params, )
import com.facebook.ads.sdk.*; import java.io.File; import java.util.Arrays; public class SAMPLE_CODE_EXAMPLE { public static void main (String args[]) throws APIException { String access_token = \"<ACCESS_TOKEN>\"; String app_secret = \"<APP_SECRET>\"; String app_id = \"<APP_ID>\"; String id = \"<ID>\"; APIContext context = new APIContext(access_token).enableDebug(true); new AdAccount(id, context).createAdCreative() .setName(\"Creative\") .setObjectStorySpec( new AdCreativeObjectStorySpec() .setFieldLinkData( new AdCreativeLinkData() .setFieldCallToAction( new AdCreativeLinkDataCallToAction() .setFieldType(AdCreativeLinkDataCallToAction.EnumType.VALUE_LIKE_PAGE) .setFieldValue( new AdCreativeLinkDataCallToActionValue() .setFieldPage(\"<pageID>\") ) ) .setFieldImageHash(\"<imageHash>\") .setFieldLink(\"https://facebook.com/<pageID>\") .setFieldMessage(\"Creative message\") ) .setFieldPageId(\"<pageID>\") ) .execute(); } }
access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end ad_account = FacebookAds::AdAccount.get(id) ad_account.adcreatives.create({ name: 'Creative', object_story_spec: {'page_id':'<pageID>','link_data':{'image_hash':'<imageHash>','link':'https:\/\/facebook.com\/<pageID>','message':'Creative message','call_to_action':{'type':'LIKE_PAGE','value':{'page':'<pageID>'}}}}, })