Event and Local Ads

Event Ads can be used by anyone interested in promoting any event on Facebook. We offer two types of event ads that provide people with relevant event details and a call-to action to attend or buy tickets to your event. Increase awareness and drive event responses. And send people to your website to buy tickets.

Local Ads help local bricks-and-mortar and service businesses reach local customers efficiently. It enables targeting based on a radius around a location and you can reach people based on the union where they live and their most recent location. With it you can use oCPM bidding maximizes reach for budget and controls frequency. See Help Center, Promote Your Local Business.

Create Event Ads

To create an event ad, you first create a campaign, an ad set and finally the ad. To create a campaign:

use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\CampaignObjectiveValues;

$campaign = new Campaign(null, 'act_<AD_ACCOUNT_ID>');
$campaign->setData(array(
  CampaignFields::NAME => 'My First Event Campaign',
  CampaignFields::OBJECTIVE => CampaignObjectiveValues::EVENT_RESPONSES,
));

$campaign->create(array(
  Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
from facebookads.adobjects.campaign import Campaign

campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
    Campaign.Field.name: 'My First Event Campaign',
    Campaign.Field.objective: Campaign.Objective.event_responses,
})

campaign.remote_create(params={
    'status': Campaign.Status.paused,
})
Campaign campaign = new AdAccount(act_<AD_ACCOUNT_ID>, context).createCampaign()
.setName("My First Event Campaign")
.setObjective(Campaign.EnumObjective.VALUE_EVENT_RESPONSES)
.setStatus(Campaign.EnumStatus.VALUE_PAUSED)
.execute();
String campaign_id = campaign.getId();
curl \
  -F 'name=My First Event Campaign' \
  -F 'objective=EVENT_RESPONSES' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/campaigns

In your request make sure you set objective to EVENT_RESPONSES. For more information about creating ads, see Marketing API Reference, Ad Campaign.

Then create an Ad Set with the optimization_goal = EVENT_RESPONSES. Also provide name, campaign_id, billing_event, targeting, lifetime_budget, bid_amount, end_time:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Values\AdSetBillingEventValues;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My Ad Set',
  AdSetFields::OPTIMIZATION_GOAL =>
    AdSetOptimizationGoalValues::EVENT_RESPONSES,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => array(
    'geo_locations' => array(
      'countries' => ['US'],
    ),
  ),
));
$adset->create();
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting

ad_account = AdAccount(fbid='act_<AD_ACCOUNT_ID>')

params = {
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.event_responses,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['US'],
        },
    },
    AdSet.Field.status: AdSet.Status.active,
}
adset = ad_account.create_ad_set(params=params)
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
.setName("My Ad Set")
.setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_EVENT_RESPONSES)
.setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
.setBidAmount(2L)
.setDailyBudget(1000L)
.setCampaignId(<CAMPAIGN_ID>)
.setTargeting(
  new Targeting()
    .setFieldGeoLocations(
      new TargetingGeoLocation()
        .setFieldCountries(Arrays.asList("US"))
    )
)
.execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My Ad Set' \
  -F 'optimization_goal=EVENT_RESPONSES' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={"geo_locations":{"countries":["US"]}}' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/adsets

See Marketing API Reference, Ad Set.

Then you provide an ad creative with images, videos or text for your ad. For object_story_spec provide your page_id and a link to the page event. For object-type, provide EVENT:

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\Values\AdCreativeObjectTypeValues;

$link_data = new AdCreativeLinkData();
$link_data->setData(array(
  AdCreativeLinkDataFields::LINK => '<EVENT_LINK>',
  AdCreativeLinkDataFields::EVENT_ID => <EVENT_ID>,
));

$story = new AdCreativeObjectStorySpec();
$story->setData(array(
  AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
  AdCreativeObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
));

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');
$creative->setData(array(
  AdCreativeFields::OBJECT_TYPE => AdCreativeObjectTypeValues::EVENT,
  AdCreativeFields::OBJECT_STORY_SPEC => $story,
));

$creative->create();
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: '<EVENT_LINK>',
    AdCreativeLinkData.Field.event_id: <EVENT_ID>,
})

story = AdCreativeObjectStorySpec()
story.update({
    AdCreativeObjectStorySpec.Field.link_data: link_data,
    AdCreativeObjectStorySpec.Field.page_id: <PAGE_ID>,
})

creative = AdCreative(parent_id='act_<AD_ACCOUNT_ID>')
creative.update({
    AdCreative.Field.object_type: AdCreative.ObjectType.event,
    AdCreative.Field.object_story_spec: story,
})

creative.remote_create()
AdCreativeLinkData linkData = new AdCreativeLinkData();
linkData.setFieldLink(<EVENT_LINK>);
linkData.setFieldEventId(event_id);
AdCreativeObjectStorySpec story = new AdCreativeObjectStorySpec();
story.setFieldLinkData(linkData);
story.setFieldPageId(<PAGE_ID>);
AdCreative creative = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdCreative()
.setObjectType(AdCreative.EnumObjectType.VALUE_EVENT.toString())
.setObjectStorySpec(story)
.execute();
String creative_id = creative.getId();

For more details, see Marketing API Reference, Ad Creative.

Now create an ad by making a post associating it to the ad set and ad creative that we created above. Make a POST to /{ad_account_id}/ads with the fields: name, creative, status, adset.

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$data = array(
  AdFields::NAME => 'My Ad',
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,
  ),
);

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
$ad->setData($data);
$ad->create(array(
  Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad[Ad.Field.name] = 'My Ad'
ad[Ad.Field.adset_id] = <AD_SET_ID>
ad[Ad.Field.creative] = {
    'creative_id': <CREATIVE_ID>,
}
ad.remote_create(params={
    'status': Ad.Status.paused,
})
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setName("My Ad")
  .setAdsetId(<AD_SET_ID>)
  .setCreative(
    new AdCreative()
      .setFieldId(<CREATIVE_ID>)
  )
  .setStatus(Ad.EnumStatus.VALUE_PAUSED)
  .execute();
curl \
  -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/v2.10/act_<AD_ACCOUNT_ID>/ads

For more details, see Marketing API Reference, Ad.

Verify in Ads Manager

Verify your ad in Ads Manager. Your campaign will have the name you used to create the campaign. The campaign will include the the ad set, ad creative and ad units.

Event Advertising for Tickets - Website Clicks

Event advertising can send people to your website to buy tickets if you want to drive ticket sales. You must have a ticket URL listed on your event to create these ads. The call to action for this ad unit is Get Tickets which take` people to an external ticket site where they can purchase the tickets.

First create a campaign, and ad set and finally the ad. To create a campaign:

use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\CampaignObjectiveValues;

$campaign = new Campaign(null, 'act_<AD_ACCOUNT_ID>');
$campaign->setData(array(
  CampaignFields::NAME => 'My campaign',
  CampaignFields::OBJECTIVE => CampaignObjectiveValues::LINK_CLICKS,
));

$campaign->create(array(
  Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
from facebookads.adobjects.campaign import Campaign

campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
    Campaign.Field.name: 'My Campaign',
    Campaign.Field.objective: Campaign.Objective.link_clicks,
})

campaign.remote_create(params={
    'status': Campaign.Status.paused,
})
Campaign campaign = new AdAccount(act_<AD_ACCOUNT_ID>, context).createCampaign()
  .setName("My campaign")
  .setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS)
  .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
  .execute();
String campaign_id = campaign.getId();
curl \
  -F 'name=My campaign' \
  -F 'objective=LINK_CLICKS' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/campaigns

In your request make sure you set objective to EVENT_RESPONSES. For more information about creating ads, see Marketing API Reference, Ad Campaign. Then make a post request with the following parameters:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Values\AdSetBillingEventValues;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My Ad Set',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::LINK_CLICKS,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => array(
    'geo_locations' => array(
      'countries' => ['US'],
    ),
  ),
));
$adset->create();
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting

ad_account = AdAccount(fbid='act_<AD_ACCOUNT_ID>')

params = {
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.link_clicks,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['US'],
        },
    },
    AdSet.Field.status: AdSet.Status.active,
}
adset = ad_account.create_ad_set(params=params)
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
.setName("My Ad Set")
.setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_LINK_CLICKS)
.setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
.setBidAmount(2L)
.setDailyBudget(1000L)
.setCampaignId(<CAMPAIGN_ID>)
.setTargeting(
  new Targeting()
    .setFieldGeoLocations(
      new TargetingGeoLocation()
        .setFieldCountries(Arrays.asList("US"))
    )
)
.execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My Ad Set' \
  -F 'optimization_goal=LINK_CLICKS' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={"geo_locations":{"countries":["US"]}}' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/adsets

For more details, see Marketing API Reference, Ad Set. Now, make a post for the page and event with the following parameters for the ad creative. You can create an ad creative with a single image, video or multiple images.

object_story_spec =
  {'page_id':271658273172455,
   'link_data':{
     'link':'www.developers.facebook.com',
     'event_id':573726539471531,
     'call_to_action':{
         value:{'link':'www.developers.facebook.com'},'type':'BUY_TICKETS'}
   }}

For more details, see Marketing API Reference, Ad Creative. Now create an ad by making a post associating it to the ad set and ad creative that we created above. Make a POST to /{ad_account_id}/ads with the fields: name, creative, status, adset.

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$data = array(
  AdFields::NAME => 'My Ad',
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,
  ),
);

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
$ad->setData($data);
$ad->create(array(
  Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad[Ad.Field.name] = 'My Ad'
ad[Ad.Field.adset_id] = <AD_SET_ID>
ad[Ad.Field.creative] = {
    'creative_id': <CREATIVE_ID>,
}
ad.remote_create(params={
    'status': Ad.Status.paused,
})
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setName("My Ad")
  .setAdsetId(<AD_SET_ID>)
  .setCreative(
    new AdCreative()
      .setFieldId(<CREATIVE_ID>)
  )
  .setStatus(Ad.EnumStatus.VALUE_PAUSED)
  .execute();
curl \
  -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/v2.10/act_<AD_ACCOUNT_ID>/ads

For more details, see Marketing API Reference, Ad. Verify your ad in Ads Manager. Your campaign will have the name you used to create the campaign. The campaign will include the the ad set, ad creative and ad units.

Event Advertising to Buy Tickets - Website Conversions

Instead of using website clicks as your objective for event ticket sales, you can track activities people take on the site like viewing the cart or completing a purchase. With this data you can later create a custom or lookalike audiences. To create this event ad, you first create a campaign, and ad set and finally the ad. To create a campaign:

use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\CampaignObjectiveValues;

$campaign = new Campaign(null, 'act_<AD_ACCOUNT_ID>');
$campaign->setData(array(
  CampaignFields::NAME => 'Conversions Campaign',
  CampaignFields::OBJECTIVE => CampaignObjectiveValues::CONVERSIONS,
));

$campaign->create(array(
  Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
from facebookads.adobjects.campaign import Campaign

campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
    Campaign.Field.name: 'Conversions Campaign',
    Campaign.Field.objective: Campaign.Objective.conversions,
})

campaign.remote_create(params={
    'status': Campaign.Status.paused,
})
Campaign campaign = new AdAccount(act_<AD_ACCOUNT_ID>, context).createCampaign()
  .setName("Conversions Campaign")
  .setObjective(Campaign.EnumObjective.VALUE_CONVERSIONS)
  .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
  .execute();
String campaign_id = campaign.getId();
curl \
  -F 'name=Conversions Campaign' \
  -F 'objective=CONVERSIONS' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/campaigns

In your request make sure you set objective to EVENT_RESPONSES. For more information about creating ads, see Marketing API Reference, Ad Campaign. Then create an ad set:

  • POST: /{ad_account_id}/adsets
  • Fields: name, campaign_id, optimization_goal = OFFSITE_CONVERSIONS, billing_event, targeting, lifetime_budget, bid_amount, end_time, promoted_object = {pixel_id, custom_event_type}

If you want to target people that are connected through pages/apps/events, specify the targeting:connections field as shown below. In this case, people that are going to the event with id: 1700354713548840 are targeted as audience for the ad.

{'geo_locations':{'countries':['US']},'connections':[{'id':1700354713548840}]}

For more details, see Marketing API Reference, Ad Set. Finally, make an ad creative using the following parameters. You can create an ad creative with a single image, video or multiple images.

Use the picture param to point to the link to be used as the image. In the example below, since there is no picture param, the default image will be scraped from the link.

object_story_spec =
  {'page_id':271658273172455,
   'link_data':{
     'link':'www.developers.facebook.com',
     'event_id':573726539471531,
     'call_to_action':{
         value:{
           'link':'www.developers.facebook.com'},
           'type':'BUY_TICKETS',
           'event_id':573726539471531}
   }}

For a carousel ad creative, use the child_attachments param to specify details that go into each card in the carousel. The link_data:link refers to the url for the final card in the carousel. The child_attachments:link refer to the links to be linked to for image cards 1/2/3/4/5 in the carousel. picture is the URL of the picture to be used for an image card in the carousel:

{'page_id':271658273172455,
 'link_data':{
   'child_attachments':[
     {'link':'www.amazon.com/Radhikas-Homework-Fairy-Ramya-Sethuraman/dp/8416484465',
      'picture':'http://41.media.tumblr.com/db095de624a109f76a125a3ccd280c49/tumblr_n3fa9i4vMC1txvp9eo1_1280.jpg',
      'call_to_action':{
         'value':{'event_id':1700354713548840},
         'type':'BUY_TICKETS'}},
     {'link':'www.amazon.com/Radhikas-Homework-Fairy-Ramya-Sethuraman/dp/8416484465',
      'picture':'https://s-media-cache-ak0.pinimg.com/236x/71/e9/03/71e903c620467816f90cad0c9d1eacbb.jpg',
      'call_to_action':{
         'value':{'event_id':1700354713548840},
         'type':'BUY_TICKETS'}}],
     'link':'www.developers.facebook.com',
     'event_id':573726539471531,
   }}

For a video ad creative, use the video_data field to specify required parameters:

  • object_story_spec: page_id, video_data {title, image_url, video_id, call_to_action}
  • image_url = thumbnail of the video to show
  • title = title to show on the ad unit
  • video_id = Scraped from the url of the page video. For e.g.: https://www.facebook.com/radhikabookseries/videos/273722849632664/

For more details, see Marketing API Reference, Ad Creative. Now create an ad by making a post associating it to the ad set and ad creative that we created above. Make a POST to /{ad_account_id}/ads with the fields: name, creative, status, adset.

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$data = array(
  AdFields::NAME => 'My Ad',
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,
  ),
);

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
$ad->setData($data);
$ad->create(array(
  Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad[Ad.Field.name] = 'My Ad'
ad[Ad.Field.adset_id] = <AD_SET_ID>
ad[Ad.Field.creative] = {
    'creative_id': <CREATIVE_ID>,
}
ad.remote_create(params={
    'status': Ad.Status.paused,
})
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setName("My Ad")
  .setAdsetId(<AD_SET_ID>)
  .setCreative(
    new AdCreative()
      .setFieldId(<CREATIVE_ID>)
  )
  .setStatus(Ad.EnumStatus.VALUE_PAUSED)
  .execute();
curl \
  -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/v2.10/act_<AD_ACCOUNT_ID>/ads

For more details, see Marketing API Reference, Ad. Verify your ad in Ads Manager. Your campaign will have the name you used to create the campaign. The campaign will include the the ad set, ad creative and ad units.

Optimize Event Ticket Sales on Facebook

You can drive ticket sales directly from your Facebook event page. You must have tickets published to your Facebook event from a qualified ticketing partner to create these ads.

The call to action is a Get Tickets button which opens the checkout flow in Facebook. To create a campaign:

use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\CampaignObjectiveValues;

$campaign = new Campaign(null, 'act_<AD_ACCOUNT_ID>');
$campaign->setData(array(
  CampaignFields::NAME => 'Conversions Campaign',
  CampaignFields::OBJECTIVE => CampaignObjectiveValues::CONVERSIONS,
));

$campaign->create(array(
  Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
from facebookads.adobjects.campaign import Campaign

campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
    Campaign.Field.name: 'Conversions Campaign',
    Campaign.Field.objective: Campaign.Objective.conversions,
})

campaign.remote_create(params={
    'status': Campaign.Status.paused,
})
Campaign campaign = new AdAccount(act_<AD_ACCOUNT_ID>, context).createCampaign()
  .setName("Conversions Campaign")
  .setObjective(Campaign.EnumObjective.VALUE_CONVERSIONS)
  .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
  .execute();
String campaign_id = campaign.getId();
curl \
  -F 'name=Conversions Campaign' \
  -F 'objective=CONVERSIONS' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/campaigns

In your request make sure you set objective to EVENT_RESPONSES. For more information about creating ads, see Marketing API Reference, Ad Campaign.

To create an ad set, make a post with the following parameters:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Values\AdSetBillingEventValues;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My Ad Set',
  AdSetFields::OPTIMIZATION_GOAL =>
    AdSetOptimizationGoalValues::OFFSITE_CONVERSIONS,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => array(
    'geo_locations' => array(
      'countries' => ['US'],
    ),
  ),
  AdSetFields::PROMOTED_OBJECT => array(
    'event_id' => <EVENT_ID>,
    'pixel_id' => <PIXEL_ID>,
    'application_id' => $app_id,
    'custom_event_type' => 'PURCHASE',
  ),
));
$adset->create();
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting

ad_account = AdAccount(fbid='act_<AD_ACCOUNT_ID>')

params = {
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.offsite_conversions,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['US'],
        },
    },
    AdSet.Field.promoted_object: {
        'event_id': <EVENT_ID>,
        'pixel_id': <PIXEL_ID>,
        'application_id': app_id,
        'custom_event_type': 'PURCHASE',
    },
    AdSet.Field.status: AdSet.Status.active,
}
adset = ad_account.create_ad_set(params=params)
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
.setName("My Ad Set")
.setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_OFFSITE_CONVERSIONS)
.setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
.setBidAmount(2L)
.setDailyBudget(1000L)
.setCampaignId(<CAMPAIGN_ID>)
.setTargeting(
  new Targeting()
    .setFieldGeoLocations(
      new TargetingGeoLocation()
        .setFieldCountries(Arrays.asList("US"))
    )
)
.setPromotedObject(
  "{\"event_id\": \"" + <EVENT_ID> + "\"," +
  "\"pixel_id\": \"" + <PIXEL_ID> + "\"," + 
  "\"application_id\": \"" + app_id + "\"," +
  "\"custom_event_type\": \"PURCHASE\"}"
)
.execute();
String ad_set_id = adSet.getId();
  • POST: /{ad_account_id}/adsets
  • Fields: name, campaign_id, optimization_goal = OFFSITE_CONVERSIONS, billing_event, targeting, lifetime_budget, bid_amount, end_time, promoted_object = {pixel_id, custom_event_type}

If you want to target people that are connected through pages/apps/events, you can specify the targeting:connections field as shown below: in this case, people that are going to the event with id: 1700354713548840 are targeted as audience for the ad.

{'geo_locations':{'countries':['US']},'connections':[{'id':1700354713548840}]}

For more details, see Marketing API Reference, Ad Set. Provide ad creative using the following parameters. You can create an ad creative with a single image, video or multiple images.

Use the picture param to point to the link to be used as the image. In the example, since there is no picture param, the default image will be scraped from the link.

object_story_spec =
  {'page_id': 955734727771665,
   'link_data':{
     'link':'www.facebook.com/events/736554086485023',
     'event_id': 736554086485023,
     'call_to_action':{
         value:{
           'link':'www.facebook.com/events/736554086485023',
           'event_id': 736554086485023
         },
         'type':'BUY_TICKETS'
      }
   }}

For more details, see Marketing API Reference, Ad Creative. Now create an ad by making a post associating it to the ad set and ad creative that we created above. Make a POST to /{ad_account_id}/ads with the fields: name, creative, status, adset.

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$data = array(
  AdFields::NAME => 'My Ad',
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,
  ),
);

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
$ad->setData($data);
$ad->create(array(
  Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad[Ad.Field.name] = 'My Ad'
ad[Ad.Field.adset_id] = <AD_SET_ID>
ad[Ad.Field.creative] = {
    'creative_id': <CREATIVE_ID>,
}
ad.remote_create(params={
    'status': Ad.Status.paused,
})
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setName("My Ad")
  .setAdsetId(<AD_SET_ID>)
  .setCreative(
    new AdCreative()
      .setFieldId(<CREATIVE_ID>)
  )
  .setStatus(Ad.EnumStatus.VALUE_PAUSED)
  .execute();
curl \
  -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/v2.10/act_<AD_ACCOUNT_ID>/ads

For more details, see Marketing API Reference, Ad. Finally, verify your ad in Ads Manager. Your campaign will have the name you used to create the campaign. The campaign will include the the ad set, ad creative and ad units.

Creating Local Ads

Create an ad campaign with objective set to REACH, see Reference: Campaign

use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\CampaignObjectiveValues;

$campaign = new Campaign(null, 'act_<AD_ACCOUNT_ID>');
$campaign->setData(array(
  CampaignFields::NAME => 'Local ad campaign',
  CampaignFields::OBJECTIVE => CampaignObjectiveValues::REACH,
));

$campaign->create(array(
  Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
from facebookads.adobjects.campaign import Campaign

campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
    Campaign.Field.name: 'Local awareness campaign',
    Campaign.Field.objective: Campaign.Objective.reach,
})

campaign.remote_create(params={
    'status': Campaign.Status.paused,
})
Campaign campaign = new AdAccount(act_<AD_ACCOUNT_ID>, context).createCampaign()
  .setName("Local awareness campaign")
  .setObjective(Campaign.EnumObjective.VALUE_LOCAL_AWARENESS)
  .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
  .execute();
String campaign_id = campaign.getId();
curl \
  -F 'name=Local ad campaign' \
  -F 'objective=REACH' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/campaigns

Then create an ad set to contain your ad. With the REACH objective:

  • The optimization_goal must be REACH.
  • The billing_event must be IMPRESSIONS.
  • The promoted_object must include the page_id of the business you are advertising.
  • The targeting_specs must include any combination of geo_locations, with the exclusion of countries. All locations in the ad set must be in the same country.

To target people who live or are visiting the area 10 miles around 1601 Willow Road Menlo Park CA, and excludes the zip code 94040:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Values\AdSetBillingEventValues;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'Local ad adset',
  AdSetFields::DAILY_BUDGET => 10000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 300,
  AdSetFields::PROMOTED_OBJECT => array(
    'page_id' => <PAGE_ID>,
  ),
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::PUBLISHER_PLATFORMS => array('facebook',),
    TargetingFields::DEVICE_PLATFORMS => array('mobile'),
    TargetingFields::GEO_LOCATIONS => array(
      'custom_locations' => array(
        array(
          'latitude' => 37.48327,
          'longitude' => -122.15033,
          'radius' => 10,
          'distance_unit' => 'mile',
          'address_string' => '1601 Willow Road, Menlo Park, CA 94025',
        ),
      ),
      'location_types' => array(
        'home',
        'recent',
      ),
    ),
    TargetingFields::EXCLUDED_GEO_LOCATIONS => array(
      'zips' => array(
        array(
          'key' => 'US:94040',
        ),
      ),
    ),
  )),
));

$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adset import AdSet

ad_account = AdAccount(fbid='act_<AD_ACCOUNT_ID>')

params = {
    AdSet.Field.name: 'Local awareness adset',
    AdSet.Field.daily_budget: 10000,
    AdSet.Field.campaign_id: '<CAMPAIGN_ID>',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 300,
    AdSet.Field.promoted_object: {
        'page_id': <PAGE_ID>,
    },
    AdSet.Field.targeting: {
        Targeting.Field.publisher_platforms: ['facebook'],
        Targeting.Field.device_platforms: ['mobile'],
        'geo_locations': {
            'custom_locations': [
                {
                    'latitude': 37.48327,
                    'longitude': -122.15033,
                    'radius': 10,
                    'distance_unit': 'mile',
                    'address_string': '1601 Willow Road, Menlo Park, CA 94025',
                },
            ],
            'location_types': [
                'home',
                'recent',
            ],
        },
        'excluded_geo_locations': {
            'zips': [
                {
                    'key': 'US:94040',
                },
            ],
        },
    },
    AdSet.Field.status: AdSet.Status.active,
}
adset = ad_account.create_ad_set(params=params)
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("Local awareness adset")
  .setDailyBudget(10000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(300L)
  .setPromotedObject("{\"page_id\":\"" + <PAGE_ID> + "\"}")
  .setTargeting(
    new Targeting()
      .setFieldDevicePlatforms(Arrays.asList(Targeting.EnumDevicePlatforms.VALUE_MOBILE))
      .setFieldExcludedGeoLocations(
        new TargetingGeoLocation()
          .setFieldZips(Arrays.asList(
            new TargetingGeoLocationZip()
              .setFieldKey("US:94040")
          ))
      )
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCustomLocations(Arrays.asList(
            new TargetingGeoLocationCustomLocation()
              .setFieldAddressString("1601 Willow Road, Menlo Park, CA 94025")
              .setFieldDistanceUnit("mile")
              .setFieldLatitude((double) 37.48327)
              .setFieldLongitude((double) -122.15033)
              .setFieldRadius((double) 10)
          ))
          .setFieldLocationTypes(Arrays.asList("home", "recent"))
      )
      .setFieldPublisherPlatforms(Arrays.asList("facebook"))
  )
  .setStatus(AdSet.EnumStatus.VALUE_PAUSED)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=Local ad adset' \
  -F 'daily_budget=10000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=300' \
  -F 'promoted_object={"page_id":"<PAGE_ID>"}' \
  -F 'targeting={ 
    "device_platforms": ["mobile"], 
    "excluded_geo_locations": {"zips":[{"key":"US:94040"}]}, 
    "geo_locations": { 
      "custom_locations": [ 
        { 
          "latitude": 37.48327, 
          "longitude": -122.15033, 
          "radius": 10, 
          "distance_unit": "mile", 
          "address_string": "1601 Willow Road, Menlo Park, CA 94025" 
        } 
      ], 
      "location_types": ["home","recent"] 
    }, 
    "publisher_platforms": ["facebook"] 
  }' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/adsets

See the Targeting Specs for more details. With custom_locations targeting, you can fetch a suggested radius to target enough people around your business. Use adradiussuggestion in targeting search API:

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
  TargetingSearchTypes::RADIUS_SUGGESTION,
  null,
  null,
  array(
    'latitude' => 37.449478,
    'longitude' => -122.173016,
    'distance_unit' => 'kilometer',
  ));
from facebookads.adobjects.targetingsearch import TargetingSearch
params = {
    'type': 'adradiussuggestion',
    'latitude': 37.449478,
    'longitude': -122.173016,
    'distance_unit': 'kilometer',
}

resp = TargetingSearch.search(params=params)
print(resp)
curl -G \
  -d 'latitude=37.449478' \
  -d 'longitude=-122.173016' \
  -d 'distance_unit=kilometer' \
  -d 'type=adradiussuggestion' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/search

The response:

{
  "data": [
    {
      "suggested_radius": 16,
      "distance_unit": "kilometer"
    }
  ]
}

See Reference: Ad set and Reference: Targeting specs

Create an unpublished page post for your ad; link page posts are supported at this time. Video page posts are available only if you use GET_DIRECTIONS call to action. You can use only posts from the page whose id has been set as promoted object in the ad set.

Unless you use the LEARN_MORE call-to-action, link must match your business Facebook page URL. See the unpublished page post to create these page posts via the API.

You can optionally set one of the following call to actions:

Get Directions

If you set the GET_DIRECTIONS call to action, you must also set the link to be the coordinates of the store's location:

call_to_action={"type":"GET_DIRECTIONS","value":{"link":"fbgeo://{LATITUDE}, {LONGITUDE}, \"{ADDRESS}\""}}

When people click on the call to action button, they will then get a map with directions to your store's location

Call Now

If you set the CALL_NOW call to action, you must also set the telephone number you want to be called at

Call Now should always be used in combination with one of the mobile targeting options to ensure device capability to make a telephone call.

call_to_action={"type":"CALL_NOW","value":{"link":"tel:{TELEPHONE_NUMBER}"}}

Clicking on the call to action button launches the device dialer with the number pre-populated.

To format a telephone number:

  • The number must start with a plus sign ("+") and the country code: +{COUNTRY_CODE}.
  • The number should not contain non-numeric characters (with exception of the initial plus sign).

Call Now is subjected to the following limitations:

  • Your ad set age targeting should not include people younger than 18 years old.
  • If your ad set geo targeting includes multiple locations, they should all be in the same country.
  • Premium-rate phone numbers are not allowed.
  • The phone number in your ad must be from the same country with respect to your ad set target locations.

Send Message

If you set the MESSAGE_PAGE call to action, no value is necessary.

call_to_action={"type":"MESSAGE_PAGE"}

Clicking on the call to action button launches the Messenger composer to send a message to the Page. The message includes the ad photo and headline as an attachment. Link page post creation example:

use FacebookAds\Api;
use FacebookAds\Http\RequestInterface;

$params = array(
  'message' => 'Come check out our new store in Menlo Park!',
  'link' => 'https://www.facebook.com/'.<PAGE_ID>,
  'picture' => '<IMAGE_URL>',
  'published' => 0,
  'call_to_action' => array(
    'type' => AdCreativeCallToActionTypeValues::GET_DIRECTIONS,
    'value' => array(
      'link' => 'fbgeo://37.48327, -122.15033, "1601 Willow Rd Menlo Park CA"',
    ),
  ),
);

$data = Api::instance()->call(
  '/'.<PAGE_ID>.'/feed',
  RequestInterface::METHOD_POST,
  $params)->getContent();
from facebookads import FacebookAdsApi

link = 'fbgeo://37.48327, -122.15033, "1601 Willow Rd Menlo Park CA"'

params = {
    'message': 'Come check out our new store in Menlo Park!',
    'link': 'https://www.facebook.com/' + str(<PAGE_ID>),
    'picture': '<IMAGE_URL>',
    'published': 0,
    'call_to_action': {
        'type': 'GET_DIRECTIONS',
        'value': {
            'link': link,
        },
    },
}

data = FacebookAdsApi.get_default_api().\
    call('POST', (<PAGE_ID>, 'feed'), params)
curl \
  -F 'message=Come check out our new store in Menlo Park!' \
  -F 'link=https://www.facebook.com/<PAGE_ID>' \
  -F 'picture=<IMAGE_URL>' \
  -F 'published=0' \
  -F 'call_to_action={ 
    "type": "GET_DIRECTIONS", 
    "value": {"link":"fbgeo:\/\/37.48327, -122.15033, \"1601 Willow Rd Menlo Park CA\""} 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/<PAGE_ID>/feed

Video page post creation example:

use FacebookAds\Api;
use FacebookAds\Http\RequestInterface;
use FacebookAds\Object\Values\AdCreativeCallToActionTypeValues;

$params = array(
  'message' => 'Come check out our new store in Menlo Park!',
  'published' => 0,
  'call_to_action' => array(
    'type' => AdCreativeCallToActionTypeValues::GET_DIRECTIONS,
    'value' => array(
      'link' => 'fbgeo://37.48327, -122.15033, "1601 Willow Rd Menlo Park CA"',
      'link_format' => 'VIDEO_LPP',
    ),
  ),
);

$request = Api::instance()->prepareRequest(
  '/'.<PAGE_ID>.'/videos',
  RequestInterface::METHOD_POST,
  $params);

$request->setLastLevelDomain('graph-video');
$request->getFileParams()->offsetSet('source', '<VIDEO_PATH>');
$response = Api::instance()->executeRequest($request);

$data = $response->getContent();
from facebookads import FacebookAdsApi

link = 'fbgeo://37.48327, -122.15033, "1601 Willow Rd Menlo Park CA"'

params = {
    'message': 'Come check out our new store in Menlo Park!',
    'published': 0,
    'call_to_action': {
        'type': 'GET_DIRECTIONS',
        'value': {
            'link': link,
        },
    },
}

url = 'https://graph-video.facebook.com/' + FacebookAdsApi.API_VERSION
path = "/{}/videos".format(<PAGE_ID>)
files = {'source': open('<VIDEO_PATH>', 'rb')}

data = FacebookAdsApi.get_default_api().call(
    'POST',
    url + path,
    params=params,
    files=files
)
curl \
  -F 'message=Come check out our new store in Menlo Park!' \
  -F 'published=0' \
  -F 'call_to_action={ 
    "type": "GET_DIRECTIONS", 
    "value": { 
      "link": "fbgeo:\/\/37.48327, -122.15033, \"1601 Willow Rd Menlo Park CA\"", 
      "link_format": "VIDEO_LPP" 
    } 
  }' \
  -F 'source=@<VIDEO_PATH>' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph-video.facebook.com/v2.10/<PAGE_ID>/videos

See Reference: Page post. Create an ad creative using the page post id from above:

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

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');

$creative->setData(array(
  AdCreativeFields::NAME => 'Sample Promoted Post',
  AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
));

$creative->create();
from facebookads.adobjects.adcreative import AdCreative

creative = AdCreative(parent_id='act_<AD_ACCOUNT_ID>')
creative[AdCreative.Field.object_story_id] = <POST_ID>
creative[AdCreative.Field.name] = 'AdCreative with post ID'

creative.remote_create()
print(creative)
AdCreative adCreative = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdCreative()
  .setName("Sample Promoted Post")
  .setObjectStoryId(object_story_id)
  .execute();
String ad_creative_id = adCreative.getId();
curl \
  -F 'name=Sample Promoted Post' \
  -F 'object_story_id=<POST_ID>' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/adcreatives

Here’s what the ad will look like:

The call to action is GET_DIRECTIONS; when people click it they see a map with directions to the business as listed on their Facebook Page. Clicks on other parts of the ad go to the advertiser’s Facebook Page.

Optionally you can combine all the creative steps above into one by using the object_story_spec field of the ad creative.

Example video creative using object_story_spec:

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeVideoDataFields;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\AdCreativeVideoData;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Values\AdCreativeCallToActionTypeValues;

$video_data = new AdCreativeVideoData();
$video_data->setData(array(
  AdCreativeVideoDataFields::IMAGE_URL => '<THUMBNAIL_URL>',
  AdCreativeVideoDataFields::VIDEO_ID => <VIDEO_ID>,
  AdCreativeVideoDataFields::LINK_DESCRIPTION =>
    "Come check out our new store in Menlo Park!",
  AdCreativeVideoDataFields::CALL_TO_ACTION => array(
    'type' => AdCreativeCallToActionTypeValues::GET_DIRECTIONS,
    'value' => array(
      'link' => 'fbgeo://37.48327, -122.15033, "1601 Willow Rd Menlo Park CA"',
    ),
  ),
));

$story = new AdCreativeObjectStorySpec();
$story->setData(array(
  AdCreativeObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
  AdCreativeObjectStorySpecFields::VIDEO_DATA => $video_data,
));

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');
$creative->{AdCreativeFields::OBJECT_STORY_SPEC} = $story;
$creative->create();
from facebookads.adobjects.adcreativevideodata import AdCreativeVideoData
from facebookads.adobjects.adcreative import AdCreative
from facebookads.adobjects.adcreativeobjectstoryspec \
    import AdCreativeObjectStorySpec

video_data = AdCreativeVideoData()
video_data[AdCreativeVideoData.Field.image_url] = image_url
video_data[AdCreativeVideoData.Field.video_id] = <VIDEO_ID>
video_data[AdCreativeVideoData.Field.link_description]\
    = 'Come check out our new store in Menlo Park!'
video_data[AdCreativeVideoData.Field.call_to_action] = {
    'type': 'GET_DIRECTIONS',
    'value': {
        'link': 'fbgeo://37.48327, -122.15033, "1601 Willow Rd Menlo Park CA"',
    },
}

story = AdCreativeObjectStorySpec()
story[AdCreativeObjectStorySpec.Field.page_id] = <PAGE_ID>
story[AdCreativeObjectStorySpec.Field.video_data] = video_data

creative = AdCreative(parent_id='act_<AD_ACCOUNT_ID>')
creative[AdCreative.Field.object_story_spec] = story
creative.remote_create()
AdCreative adCreative = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdCreative()
  .setObjectStorySpec(
    new AdCreativeObjectStorySpec()
      .setFieldPageId(<PAGE_ID>)
      .setFieldVideoData(
        new AdCreativeVideoData()
          .setFieldCallToAction(
            new AdCreativeLinkDataCallToAction()
              .setFieldType(AdCreativeLinkDataCallToAction.EnumType.VALUE_GET_DIRECTIONS)
              .setFieldValue(
                new AdCreativeLinkDataCallToActionValue()
                  .setFieldLink("fbgeo://37.48327, -122.15033, \"1601 Willow Rd Menlo Park CA\"")
              )
          )
          .setFieldDescription("Come check out our new store in Menlo Park!")
          .setFieldImageUrl(<THUMBNAIL_URL>)
          .setFieldVideoId(<VIDEO_ID>)
      )
  )
  .execute();
String ad_creative_id = adCreative.getId();
curl \
  -F 'object_story_spec={ 
    "page_id": "<PAGE_ID>", 
    "video_data": { 
      "call_to_action": { 
        "type": "GET_DIRECTIONS", 
        "value": { 
          "link": "fbgeo:\/\/37.48327, -122.15033, \"1601 Willow Rd Menlo Park CA\"" 
        } 
      }, 
      "image_url": "<THUMBNAIL_URL>", 
      "link_description": "Come check out our new store in Menlo Park!", 
      "video_id": "<VIDEO_ID>" 
    } 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.10/act_<AD_ACCOUNT_ID>/adcreatives

See Reference: Ad creative. Finally, create an ad.

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$data = array(
  AdFields::NAME => 'My Ad',
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,
  ),
);

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
$ad->setData($data);
$ad->create(array(
  Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad[Ad.Field.name] = 'My Ad'
ad[Ad.Field.adset_id] = <AD_SET_ID>
ad[Ad.Field.creative] = {
    'creative_id': <CREATIVE_ID>,
}
ad.remote_create(params={
    'status': Ad.Status.paused,
})
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setName("My Ad")
  .setAdsetId(<AD_SET_ID>)
  .setCreative(
    new AdCreative()
      .setFieldId(<CREATIVE_ID>)
  )
  .setStatus(Ad.EnumStatus.VALUE_PAUSED)
  .execute();
curl \
  -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/v2.10/act_<AD_ACCOUNT_ID>/ads

See Reference: Ad