1. 程式人生 > >Event and Local Ads

Event and Local Ads

Create Event Ads

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

curl -X POST \
  -F 'name="My First Event Campaign"' \
  -F 'objective="EVENT_RESPONSES"' \
  -F 'status="PAUSED"' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v3.2/act_<AD_ACCOUNT_ID>/campaigns
const adsSdk = require('facebook-nodejs-ads-sdk');
const AdAccount = adsSdk.AdAccount;
const Campaign = adsSdk.Campaign;

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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'My First Event Campaign',
  'objective' : 'EVENT_RESPONSES',
  'status' : 'PAUSED',
};
let campaigns = (new AdAccount(id)).createCampaign(
  fields,
  params
);
logApiCallResult('campaigns api call complete.', campaigns);
require __DIR__ . '/vendor/autoload.php';

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
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 First Event Campaign',
  'objective' => 'EVENT_RESPONSES',
  'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createCampaign(
  $fields,
  $params
)->exportAllData(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.campaign import Campaign
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 First Event Campaign',
  'objective': 'EVENT_RESPONSES',
  'status': 'PAUSED',
}
print AdAccount(id).create_campaign(
  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).createCampaign()
      .setName(\"My First Event Campaign\")
      .setObjective(Campaign.EnumObjective.VALUE_EVENT_RESPONSES)
      .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
      .execute();

  }
}
require 'facebook_ads'

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)
campaigns = ad_account.campaigns.create({
    name: 'My First Event Campaign',
    objective: 'EVENT_RESPONSES',
    status: 'PAUSED',
})

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.adset import AdSet
from facebookads.adobjects.targeting import Targeting

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    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.remote_create()
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.11/act_<AD_ACCOUNT_ID>/adsets

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>',
})

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();

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.

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.2/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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'My Ad',
  'adset_id' : '<adSetID>',
  'creative' : {'creative_id':'<adCreativeID>'},
  'status' : 'PAUSED',
};
let ads = (new AdAccount(id)).createAd(
  fields,
  params
);
logApiCallResult('ads api call complete.', ads);
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
)->exportAllData(), 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();

  }
}
require 'facebook_ads'

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)
ads = ad_account.ads.create({
    name: 'My Ad',
    adset_id: '<adSetID>',
    creative: {'creative_id':'<adCreativeID>'},
    status: 'PAUSED',
})

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:

curl -X POST \
  -F 'name="My campaign"' \
  -F 'objective="LINK_CLICKS"' \
  -F 'status="PAUSED"' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v3.0/act_<AD_ACCOUNT_ID>/campaigns
const adsSdk = require('facebook-nodejs-ads-sdk');
const AdAccount = adsSdk.AdAccount;
const Campaign = adsSdk.Campaign;

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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'My campaign',
  'objective' : 'LINK_CLICKS',
  'status' : 'PAUSED',
};
let campaigns = (new AdAccount(id)).createCampaign(
  fields,
  params
);
logApiCallResult('campaigns api call complete.', campaigns);
require __DIR__ . '/vendor/autoload.php';

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
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 campaign',
  'objective' => 'LINK_CLICKS',
  'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createCampaign(
  $fields,
  $params
)->exportAllData(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.campaign import Campaign
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 campaign',
  'objective': 'LINK_CLICKS',
  'status': 'PAUSED',
}
print AdAccount(id).create_campaign(
  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).createCampaign()
      .setName(\"My campaign\")
      .setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS)
      .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
      .execute();

  }
}
require 'facebook_ads'

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)
campaigns = ad_account.campaigns.create({
    name: 'My campaign',
    objective: 'LINK_CLICKS',
    status: 'PAUSED',
})

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.adset import AdSet
from facebookads.adobjects.targeting import Targeting

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    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.remote_create()
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.11/act_<AD_ACCOUNT_ID>/adsets

For more details, see Marketing API Reference, Ad Set. Now, make a page post 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.

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.2/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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'My Ad',
  'adset_id' : '<adSetID>',
  'creative' : {'creative_id':'<adCreativeID>'},
  'status' : 'PAUSED',
};
let ads = (new AdAccount(id)).createAd(
  fields,
  params
);
logApiCallResult('ads api call complete.', ads);
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
)->exportAllData(), 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();

  }
}
require 'facebook_ads'

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)
ads = ad_account.ads.create({
    name: 'My Ad',
    adset_id: '<adSetID>',
    creative: {'creative_id':'<adCreativeID>'},
    status: 'PAUSED',
})

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:

curl -X POST \
  -F 'name="Conversions Campaign"' \
  -F 'objective="CONVERSIONS"' \
  -F 'status="PAUSED"' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v3.2/act_<AD_ACCOUNT_ID>/campaigns
const adsSdk = require('facebook-nodejs-ads-sdk');
const AdAccount = adsSdk.AdAccount;
const Campaign = adsSdk.Campaign;

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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'Conversions Campaign',
  'objective' : 'CONVERSIONS',
  'status' : 'PAUSED',
};
let campaigns = (new AdAccount(id)).createCampaign(
  fields,
  params
);
logApiCallResult('campaigns api call complete.', campaigns);
require __DIR__ . '/vendor/autoload.php';

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
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' => 'Conversions Campaign',
  'objective' => 'CONVERSIONS',
  'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createCampaign(
  $fields,
  $params
)->exportAllData(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.campaign import Campaign
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': 'Conversions Campaign',
  'objective': 'CONVERSIONS',
  'status': 'PAUSED',
}
print AdAccount(id).create_campaign(
  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).createCampaign()
      .setName(\"Conversions Campaign\")
      .setObjective(Campaign.EnumObjective.VALUE_CONVERSIONS)
      .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
      .execute();

  }
}
require 'facebook_ads'

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)
campaigns = ad_account.campaigns.create({
    name: 'Conversions Campaign',
    objective: 'CONVERSIONS',
    status: 'PAUSED',
})

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.

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.2/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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'My Ad',
  'adset_id' : '<adSetID>',
  'creative' : {'creative_id':'<adCreativeID>'},
  'status' : 'PAUSED',
};
let ads = (new AdAccount(id)).createAd(
  fields,
  params
);
logApiCallResult('ads api call complete.', ads);
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
)->exportAllData(), 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();

  }
}
require 'facebook_ads'

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)
ads = ad_account.ads.create({
    name: 'My Ad',
    adset_id: '<adSetID>',
    creative: {'creative_id':'<adCreativeID>'},
    status: 'PAUSED',
})

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:

curl -X POST \
  -F 'name="Conversions Campaign"' \
  -F 'objective="CONVERSIONS"' \
  -F 'status="PAUSED"' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v3.2/act_<AD_ACCOUNT_ID>/campaigns
const adsSdk = require('facebook-nodejs-ads-sdk');
const AdAccount = adsSdk.AdAccount;
const Campaign = adsSdk.Campaign;

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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'Conversions Campaign',
  'objective' : 'CONVERSIONS',
  'status' : 'PAUSED',
};
let campaigns = (new AdAccount(id)).createCampaign(
  fields,
  params
);
logApiCallResult('campaigns api call complete.', campaigns);
require __DIR__ . '/vendor/autoload.php';

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
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' => 'Conversions Campaign',
  'objective' => 'CONVERSIONS',
  'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createCampaign(
  $fields,
  $params
)->exportAllData(), JSON_PRETTY_PRINT);
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.campaign import Campaign
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': 'Conversions Campaign',
  'objective': 'CONVERSIONS',
  'status': 'PAUSED',
}
print AdAccount(id).create_campaign(
  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).createCampaign()
      .setName(\"Conversions Campaign\")
      .setObjective(Campaign.EnumObjective.VALUE_CONVERSIONS)
      .setStatus(Campaign.EnumStatus.VALUE_PAUSED)
      .execute();

  }
}
require 'facebook_ads'

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)
campaigns = ad_account.campaigns.create({
    name: 'Conversions Campaign',
    objective: 'CONVERSIONS',
    status: 'PAUSED',
})

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.adset import AdSet
from facebookads.adobjects.targeting import Targeting

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    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.attribution_window_days: 1,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['US'],
        },
    },
    AdSet.Field.promoted_object: {
        'event_id': <EVENT_ID>,
        'application_id': app_id,
        'custom_event_type': 'PURCHASE',
    },
})

adset.remote_create()
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.

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.2/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 logApiCallResult = (apiCallName, data) => {
  console.log(apiCallName);
  if (showDebugingInfo) {
    console.log('Data:' + JSON.stringify(data));
  }
};

let fields, params;
fields = [
];
params = {
  'name' : 'My Ad',
  'adset_id' : '<adSetID>',
  'creative' : {'creative_id':'<adCreativeID>'},
  'status' : 'PAUSED',
};
let ads = (new AdAccount(id)).createAd(
  fields,
  params
);
logApiCallResult('ads api call complete.', ads);
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
)->exportAllData(), 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();

  }
}
require 'facebook_ads'

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)
ads = ad_account.ads.create({
    name: 'My Ad',
    adset_id: '<adSetID>',
    creative: {'creative_id':'<adCreativeID>'},
    status: 'PAUSED',
})

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.

相關推薦

Event and Local Ads

Create Event Ads To create an event ad, you first create a campaign, an ad set and finally the ad. To create a campaign:cURLNode.js Business SDKPHP Busine

[LeetCode] Global and Local Inversions 全局與局部的倒置

BE ons length red pla return inversion UC true We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The numb

[LeetCode] Global and Local Inversions 全域性與區域性的倒置

We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) inversions is the number of i < j with 0 <= i

PAL North America announces new partnerships with three state and local governments | MIT News

J-PAL North America announced today that it will partner with three U.S. state and local governments to evaluate promising solutions related to education,

Ask HN: Is there any way an app can listen conversations secretly and show ads?

I am a person who is pretty aware of what i search what i type.I had few instances that i heard an ad on radio and chat with my wife or my friends and some

State and Local Governments in the Cloud

The New York Public Library's (NYPL's) Digital Collections platform makes available 677,496 items spanning a wide range of

Global and Local Variables

http://www.python-course.eu/python3_global_vs_local_variables.php In the following example, we want to demonstrate, how global values c

Event and Delegate

private tps pre += som function fun 編譯 委托 文章著作權歸作者所有。轉載請聯系作者,並在文中註明出處,給出原文鏈接。 本文原更新於作者的github博客,這裏給出鏈接。 委托 委托的實質是一個類。 // 委托定義 delegate Re

論文閱讀 | CrystalBall: A Visual Analytic System for Future Event Discovery and Analysis from Social Media Data

夏洛特 bstr soci 相同 方式 PE VM src 測量 CrystalBall: A Visual Analytic System for Future Event Discovery and Analysis from Social Media Data 論文地

Building Robust and Flexible Event System in Unity3D

leg die tco pen change con In PE deb Building Robust and Flexible Event System in Unity3D 1. Prerequisites 1.1 Observer Pattern According

SSH local forwarding and remote forwarding

本文作為實驗記錄,主要參考:https://www.cnblogs.com/keerya/p/7612715.html SSH埠轉發的簡單實驗: 1. SSH 遠端轉發 1.1說明:A機器(172.23.2.198),B機器(172.23.2.188),C機器(172.17.5.13

Learning Discriminative and Transformation Covariant Local Feature Detectors實驗環境搭建詳細過程

依賴項: Python 3.4.3 tensorflow>1.0.0, tqdm, cv2, exifread, skimage, glob 1、安裝tensorflow:https://www.tensorflow.org/install/pip?lang=python3 1、安裝python

Orace 12c Export local database and import to remote database

Export local database and import to remote database Export local database to dmp file Execute on sql developer client with system role alter

23.Deep Networks for Saliency Detection via Local Estimation and Global Search

Deep networks for saliency detection via Local Estimation and Global Search 摘要 本文提出了一種將區域性估計和全域性搜尋相結合的顯著性檢測演算法。在區域性估計階段,我們通過使用深度神經網路(DNN

Person Re-identification by Local Maximal Occurrence Representation and Metric Learning(LOMO+XQDA)

2015年,學術界主流都在使用深度學習,而這篇文章卻用傳統方法達到了遠超state of the art的結果: Retinex transform預處理: 為了解決不同攝像頭下光照條件變化很大:作者在特徵提取前進行了預處理,使用的是multiscale Retine

local class and nested class

local class 在一個函式裡面宣告的類從屬於那個函式。比如說 void fun() { class base { private: public: }

Nested Class,Inner Class,Member Class,Local Class, and Anonymous class區別

其實所有類都可能是top level類或是nested 類;所有的nested 類都可能是static類或是Inner類;所有的Inner類都可能是local類,Anonymous類,non-static 的Member類;top level 類不能是nested類.

Java local variables initialize and member initialize

1. In the case of a method’s local variables, if you say: void f() { int i; i++; } you’ll get an error message that says that i migh

Made by Google Event 2018: What we expect and don't expect for Pixel, Google Home and more

While it might seem like the annual Made by Google event has already taken place based on the Pixel leaks we've received on a daily basis, we actually stil