创建资源

订单项有许多父级资源,这些父级资源会沿用相关设置和定位条件。您可以使用 Display & Video 360 API 创建、检索和更新其中大部分资源。本页面介绍了资源层次结构,并举例说明了如何使用 Display & Video 360 API 创建这些资源。

资源层次结构

资源层次结构图

在 Display & Video 360 中,具有层次结构,其设置会影响广告投放。每项资源在投放广告方面的用途各不相同。从最低层级开始:

  • 订单项是资源,用于控制投放哪些广告、何时投放以及向哪些对象投放。
    • YouTube 及合作伙伴订单项还包含广告组广告子资源。它们可在单个订单项预算下提供额外的定位条件。YouTube 及合作伙伴订单项 项、广告组、广告及其定位条件无法使用 API 进行修改。
  • 广告订单包含多个订单项。它们可为不存在的订单项设置提供默认值。
  • 广告系列包含多个广告订单。也不会对其广告订单强制执行设置其设置就像框架一样,用于衡量在其名下投放的广告的进度和成功。
  • 广告客户拥有多个广告系列。它们会对在其名下投放的广告强制执行品牌保障定位和其他常规设置。并且拥有在其名下投放的广告中使用的广告素材对象,并提供对定位中所用资源的访问权限。
  • 合作伙伴拥有多个广告客户。它们会对这些广告客户强制执行进一步的品牌保障定位和其他设置。还可以访问定位中使用的资源,以及转化跟踪中使用的 Floodlight 活动。无法通过该 API 修改合作伙伴。

继承

订单项会继承其父级资源的众多设置和访问权限。 管理订单项和广告投放时,需要考虑的继承品质包括:

  • 可用的广告素材和 Floodlight 活动:订单项只能访问其父级合作伙伴或广告客户拥有的资源。广告素材在广告客户下创建,Floodlight 活动归合作伙伴所有。分配给 LineItem 资源字段 creativeIdsconversionCounting 的资源必须分别共用同一个父级广告客户和合作伙伴。
  • 可访问的实体实体:定位时会用到渠道组合的受众群体等资源。只能使用其父级合作伙伴或广告客户可访问的资源来定位订单项。
  • 品牌保障定位条件:订单项会沿用在合作伙伴级和广告客户级设置的定位条件。无法移除继承的定位条件。这种现有定位条件可通过已分配定位选项的 inheritance 字段进行标识,这会影响到可以应用哪些进一步的定位条件。

创建资源

上面列出的所有资源都可以使用 Display & Video 360 API 进行管理。下面的简单代码示例演示了如何使用提供的客户端库创建上述各项资源。

创建广告客户

下面的示例展示了如何创建广告客户

Java

// Create an advertiser object.
Advertiser advertiser = new Advertiser();
advertiser.setPartnerId(partner-id);
advertiser.setDisplayName(display-name);
advertiser.setEntityStatus("ENTITY_STATUS_ACTIVE");

// Create and set the advertiser general configuration.
AdvertiserGeneralConfig advertiserGeneralConfig = new AdvertiserGeneralConfig();
advertiserGeneralConfig.setDomainUrl(domain-url);
advertiserGeneralConfig.setCurrencyCode("USD");
advertiser.setGeneralConfig(advertiserGeneralConfig);

// Create the ad server configuration structure.
AdvertiserAdServerConfig advertiserAdServerConfig = new AdvertiserAdServerConfig();

// Create and add the third party only configuration to the ad server
// configuration.
advertiserAdServerConfig.setThirdPartyOnlyConfig(new ThirdPartyOnlyConfig());

// Set the ad server configuration.
advertiser.setAdServerConfig(advertiserAdServerConfig);

// Create and set the creative configuration.
advertiser.setCreativeConfig(new AdvertiserCreativeConfig());

// Create and set the billing configuration.
AdvertiserBillingConfig advertiserBillingConfig = new AdvertiserBillingConfig();
advertiserBillingConfig.setBillingProfileId(billing-profile-id);
advertiser.setBillingConfig(advertiserBillingConfig);

// Configure the create request.
Advertisers.Create request = service.advertisers().create(advertiser);

// Create the advertiser.
Advertiser response = request.execute();

// Display the new advertiser.
System.out.printf("Advertiser %s was created.", response.getName());

Python

# Create an advertiser object.
advertiser_obj = {
    'partnerId': partner-id,
    'displayName': display-name,
    'entityStatus': "ENTITY_STATUS_ACTIVE",
    'generalConfig': {
        'domainUrl' : domain-url,
        'currencyCode' : 'USD'
    },
    'adServerConfig': {
        'thirdPartyOnlyConfig' : {}
    },
    'creativeConfig': {},
    'billingConfig': {
        'billingProfileId' : billing-profile-id
    }
}

# Create the advertiser.
advertiser = service.advertisers().create(
    body=advertiser_obj
).execute()

# Display the new advertiser.
print("Advertiser %s was created." % advertiser["name"])

PHP

// Create an advertiser object.
$advertiser = new Google_Service_DisplayVideo_Advertiser();
$advertiser->setPartnerId(partner-id);
$advertiser->setDisplayName(display-name);
$advertiser->setEntityStatus('ENTITY_STATUS_ACTIVE');

// Create and set the advertiser general configuration.
$generalConfig =
    new Google_Service_DisplayVideo_AdvertiserGeneralConfig();
$generalConfig->setDomainUrl(domain-url);
$generalConfig->setCurrencyCode('USD');
$advertiser->setGeneralConfig($generalConfig);

// Create the ad server configuration structure.
$adServerConfig =
    new Google_Service_DisplayVideo_AdvertiserAdServerConfig();

// Create and add the third party only configuration to the ad server
// configuration.
$adServerConfig->setThirdPartyOnlyConfig(
    new Google_Service_DisplayVideo_ThirdPartyOnlyConfig()
);

// Set the ad server configuration.
$advertiser->setAdServerConfig($adServerConfig);

// Create and set the creative configuration.
$advertiser->setCreativeConfig(
    new Google_Service_DisplayVideo_AdvertiserCreativeConfig()
);

// Create and set the billing configuration.
$billingConfig = new Google_Service_DisplayVideo_AdvertiserBillingConfig();
$billingConfig->setBillingProfileId(billing-profile-id);
$advertiser->setBillingConfig($billingConfig);

// Call the API, creating the advertiser.
$result = $this->service->advertisers->create($advertiser);

printf('Advertiser %s was created.\n', $result['name']);

制作广告系列

下面的示例展示了如何制作广告系列

Java

// Create a campaign object.
Campaign campaign = new Campaign();
campaign.setDisplayName(display-name);
campaign.setEntityStatus("ENTITY_STATUS_PAUSED");

// Create a campaign goal object.
CampaignGoal campaignGoal = new CampaignGoal();
campaignGoal.setCampaignGoalType("CAMPAIGN_GOAL_TYPE_BRAND_AWARENESS");

// Create and add a performance goal to the campaign goal object.
PerformanceGoal performanceGoal = new PerformanceGoal();
performanceGoal.setPerformanceGoalType("PERFORMANCE_GOAL_TYPE_CPC");
performanceGoal.setPerformanceGoalAmountMicros(1000000L);
campaignGoal.setPerformanceGoal(performanceGoal);

// Set the campaign goal.
campaign.setCampaignGoal(campaignGoal);

// Create a campaign flight object.
// This object details the planned spend and duration of the campaign.
CampaignFlight campaignFlight = new CampaignFlight();
campaignFlight.setPlannedSpendAmountMicros(1000000L);

// Create the date range for the campaign flight.
DateRange dateRange = new DateRange();

// Set the start date to one week from now and the end date to two weeks
// from now.
Calendar calendarStartDate = Calendar.getInstance().add(Calendar.DATE, 7);
Calendar calendarEndDate = Calendar.getInstance().add(Calendar.DATE, 14);
dateRange.setStartDate(
   new Date()
      .setYear(calendarStartDate.get(Calendar.YEAR))
      .setMonth(calendarStartDate.get(Calendar.MONTH))
      .setDay(calendarStartDate.get(Calendar.DAY_OF_MONTH)));
dateRange.setEndDate(
   new Date()
      .setYear(calendarEndDate.get(Calendar.YEAR))
      .setMonth(calendarEndDate.get(Calendar.MONTH))
      .setDay(calendarEndDate.get(Calendar.DAY_OF_MONTH)));

// Add the planned date range to the campaign flight object.
campaignFlight.setPlannedDates(dateRange);

// Set the campaign flight.
campaign.setCampaignFlight(campaignFlight);

// Create and set the frequency cap.
FrequencyCap frequencyCap = new FrequencyCap();
frequencyCap.setMaxImpressions(10);
frequencyCap.setTimeUnit("TIME_UNIT_DAYS");
frequencyCap.setTimeUnitCount(1);
campaign.setFrequencyCap(frequencyCap);

// Configure the create request.
Campaigns.Create request = service.advertisers().campaigns()
   .create(advertiser-id, campaign);

// Create the campaign.
Campaign response = request.execute();

// Display the new campaign.
System.out.printf("Campaign %s was created.", response.getName());

Python

# Create a future campaign flight start and end dates.
startDate = date.today() + timedelta(days=7)
endDate = date.today() + timedelta(days=14)

# Create a campaign object.
campaign_obj = {
    'displayName': display-name,
    'entityStatus': 'ENTITY_STATUS_PAUSED',
    'campaignGoal': {
        'campaignGoalType' : 'CAMPAIGN_GOAL_TYPE_BRAND_AWARENESS',
        'performanceGoal': {
            'performanceGoalType': 'PERFORMANCE_GOAL_TYPE_CPC',
            'performanceGoalAmountMicros': 1000000
        }
    },
    'campaignFlight': {
        'plannedSpendAmountMicros': 1000000,
        'plannedDates': {
            'startDate': {
                'year': startDate.year,
                'month': startDate.month,
                'day': startDate.day
            },
            'endDate': {
                'year': endDate.year,
                'month': endDate.month,
                'day': endDate.day
            }
        }
    },
    'frequencyCap': {
        'maxImpressions': 10,
        'timeUnit': 'TIME_UNIT_DAYS',
        'timeUnitCount': 1
    }
}

# Create the campaign.
campaign = service.advertisers().campaigns().create(
    advertiserId=advertiser-id,
    body=campaign_obj
).execute()

# Display the new campaign.
print("Campaign %s was created." % campaign["name"])

PHP

// Create a campaign object.
$campaign = new Google_Service_DisplayVideo_Campaign();
$campaign->setDisplayName(display-name);
$campaign->setEntityStatus('ENTITY_STATUS_ACTIVE');

// Create a campaign goal object.
$campaignGoal = new Google_Service_DisplayVideo_CampaignGoal();
$campaignGoal->setCampaignGoalType(
    'CAMPAIGN_GOAL_TYPE_BRAND_AWARENESS'
);

// Create and add a performance goal to the campaign goal object.
$performanceGoal = new Google_Service_DisplayVideo_PerformanceGoal();
$performanceGoal->setPerformanceGoalType('PERFORMANCE_GOAL_TYPE_CPC');
$performanceGoal->setPerformanceGoalAmountMicros(1000000);

// Set the campaign goal.
$campaignGoal->setPerformanceGoal($performanceGoal);
$campaign->setCampaignGoal($campaignGoal);

// Create a campaign flight object.
// This object details the planned spend and duration of the campaign.
$campaignFlight = new Google_Service_DisplayVideo_CampaignFlight();
$campaignFlight->setPlannedSpendAmountMicros(1000000);

// Create a date range object for the flight.
$dateRange = new Google_Service_DisplayVideo_DateRange();

// Create and assign a start date one week from now.
$startDateTime = new DateTime('today + 7 days');
$startDate = new Google_Service_DisplayVideo_Date();
$startDate->setYear($startDateTime->format('Y'));
$startDate->setMonth($startDateTime->format('n'));
$startDate->setDay($startDateTime->format('j'));
$dateRange->setStartDate($startDate);

// Create and assign an end date two weeks from now.
$endDateTime = new DateTime('today + 14 days');
$endDate = new Google_Service_DisplayVideo_Date();
$endDate->setYear($endDateTime->format('Y'));
$endDate->setMonth($endDateTime->format('n'));
$endDate->setDay($endDateTime->format('j'));
$dateRange->setendDate($endDate);

// Assign date range to flight.
$campaignFlight->setPlannedDates($dateRange);

// Assign flight to campaign.
$campaign->setCampaignFlight($campaignFlight);

// Create and set the frequency cap.
$frequencyCap = new Google_Service_DisplayVideo_FrequencyCap();
$frequencyCap->setMaxImpressions(10);
$frequencyCap->setTimeUnit('TIME_UNIT_DAYS');
$frequencyCap->setTimeUnitCount(1);
$campaign->setFrequencyCap($frequencyCap);

// Call the API, creating the campaign under the given advertiser.
$result = $this->service->advertisers_campaigns->create(
    advertiser-id,
    $campaign
);

// Display the new campaign.
printf('Campaign %s was created.\n', $result['name']);

创建广告订单

下面的示例展示了如何创建广告订单

Java

// Create an insertion order object.
InsertionOrder insertionOrder = new InsertionOrder();
insertionOrder.setCampaignId(campaign-id);
insertionOrder.setDisplayName(display-name);
insertionOrder.setEntityStatus("ENTITY_STATUS_DRAFT");

// Create and add the pacing setting.
Pacing pacing = new Pacing();
pacing.setPacingPeriod("PACING_PERIOD_DAILY");
pacing.setPacingType("PACING_TYPE_EVEN");
pacing.setDailyMaxMicros(10000L);
insertionOrder.setPacing(pacing);

// Create and set the frequency cap.
FrequencyCap frequencyCap = new FrequencyCap();
frequencyCap.setTimeUnit("TIME_UNIT_DAYS");
frequencyCap.setTimeUnitCount(1);
frequencyCap.setMaxImpressions(10);
insertionOrder.setFrequencyCap(frequencyCap);

// Create and set the key performance indicator (KPI).
Kpi kpi = new Kpi();
kpi.setKpiType("KPI_TYPE_CPC");
kpi.setKpiAmountMicros(1000000L);
insertionOrder.setKpi(kpi);

// Create a budget object.
InsertionOrderBudget insertionOrderBudget = new InsertionOrderBudget();
insertionOrderBudget.setBudgetUnit("BUDGET_UNIT_CURRENCY");

// Create a budget segment object.
InsertionOrderBudgetSegment insertionOrderBudgetSegment =
   new InsertionOrderBudgetSegment();
insertionOrderBudgetSegment.setBudgetAmountMicros(100000L);

// Create the date range for the budget segment.
DateRange dateRange = new DateRange();

// Set the start date to one week from now and the end date to two weeks
// from now.
Calendar calendarStartDate = Calendar.getInstance().add(Calendar.DATE, 7);
Calendar calendarEndDate = Calendar.getInstance().add(Calendar.DATE, 14);
dateRange.setStartDate(
   new Date()
      .setYear(calendarStartDate.get(Calendar.YEAR))
      .setMonth(calendarStartDate.get(Calendar.MONTH))
      .setDay(calendarStartDate.get(Calendar.DAY_OF_MONTH)));
dateRange.setEndDate(
   new Date()
      .setYear(calendarEndDate.get(Calendar.YEAR))
      .setMonth(calendarEndDate.get(Calendar.MONTH))
      .setDay(calendarEndDate.get(Calendar.DAY_OF_MONTH)));

// Add the date range to the budget segment.
insertionOrderBudgetSegment.setDateRange(dateRange);

// Add budget segment list to the budget.
insertionOrderBudget
   .setBudgetSegments(ImmutableList.of(insertionOrderBudgetSegment));

// Set budget.
insertionOrder.setBudget(insertionOrderBudget);

// Configure the create request.
InsertionOrders.Create request =
   service.advertisers().insertionOrders()
       .create(advertiser-id, insertionOrder);

// Create the insertion order.
InsertionOrder response = request.execute();

// Display the new insertion order.
System.out.printf("InsertionOrder %s was created.", response.getName());

Python

# Create a future budget segment start and end dates.
startDate = date.today() + timedelta(days=7)
endDate = date.today() + timedelta(days=14)

# Create an insertion order object.
insertion_order_obj = {
    'campaignId' : campaign-id,
    'displayName': display-name,
    'entityStatus': 'ENTITY_STATUS_DRAFT',
    'pacing': {
        'pacingPeriod': 'PACING_PERIOD_DAILY',
        'pacingType': 'PACING_TYPE_EVEN',
        'dailyMaxMicros': 10000
    },
    'frequencyCap': {
        'maxImpressions': 10,
        'timeUnit': 'TIME_UNIT_DAYS',
        'timeUnitCount': 1
    },
    'kpi' : {
        'kpiType': 'KPI_TYPE_CPC',
        'kpiAmountMicros': 1000000
    },
    'budget': {
        'budgetUnit': 'BUDGET_UNIT_CURRENCY',
        'budgetSegments': [
            {
                'budgetAmountMicros': 100000,
                'dateRange': {
                    'startDate': {
                        'year': startDate.year,
                        'month': startDate.month,
                        'day': startDate.day
                    },
                    'endDate': {
                        'year': endDate.year,
                        'month': endDate.month,
                        'day': endDate.day
                    }
                }
            }
        ]
    }
}

# Create the insertion order.
insertionOrder = service.advertisers().insertionOrders().create(
    advertiserId=advertiser-id,
    body=insertion_order_obj
).execute()

# Display the new insertion order.
print("Insertion Order %s was created." % insertionOrder["name"])

PHP

// Create an insertion order object.
$insertionOrder = new Google_Service_DisplayVideo_InsertionOrder();
$insertionOrder->setCampaignId(campaign-id);
$insertionOrder->setDisplayName(display-name);
$insertionOrder->setEntityStatus('ENTITY_STATUS_DRAFT');

// Create and add the pacing setting.
$pacing = new Google_Service_DisplayVideo_Pacing();
$pacing->setPacingPeriod('PACING_PERIOD_DAILY');
$pacing->setPacingType('PACING_TYPE_EVEN');
$pacing->setDailyMaxMicros(10000);
$insertionOrder->setPacing($pacing);

// Create and set the frequency cap.
$frequencyCap = new Google_Service_DisplayVideo_FrequencyCap();
$frequencyCap->setMaxImpressions(10);
$frequencyCap->setTimeUnit('TIME_UNIT_DAYS');
$frequencyCap->setTimeUnitCount(1);
$insertionOrder->setFrequencyCap($frequencyCap);

// Create and set the key performance indicator (KPI).
$kpi = new Google_Service_DisplayVideo_Kpi();
$kpi->setKpiType('KPI_TYPE_CPC');
$kpi->setKpiAmountMicros(1000000);
$insertionOrder->setKpi($kpi);

// Create a budget object.
$budget = new Google_Service_DisplayVideo_InsertionOrderBudget();
$budget->setBudgetUnit('BUDGET_UNIT_CURRENCY');

// Create a budget segment object.
$budgetSegment =
    new Google_Service_DisplayVideo_InsertionOrderBudgetSegment();
$budgetSegment->setBudgetAmountMicros(100000);

// Create a date range object for the budget segment.
$dateRange = new Google_Service_DisplayVideo_DateRange();

// Create and assign a start date one week from now.
$startDateTime = new DateTime('today + 7 days');
$startDate = new Google_Service_DisplayVideo_Date();
$startDate->setYear($startDateTime->format('Y'));
$startDate->setMonth($startDateTime->format('n'));
$startDate->setDay($startDateTime->format('j'));
$dateRange->setStartDate($startDate);

// Create and assign an end date two weeks from now.
$endDateTime = new DateTime('today + 14 days');
$endDate = new Google_Service_DisplayVideo_Date();
$endDate->setYear($endDateTime->format('Y'));
$endDate->setMonth($endDateTime->format('n'));
$endDate->setDay($endDateTime->format('j'));
$dateRange->setendDate($endDate);

// Assign date range to budget segment.
$budgetSegment->setDateRange($dateRange);

// Set budget segment.
$budget->setBudgetSegments(array($budgetSegment));

// Set budget object.
$insertionOrder->setBudget($budget);

// Call the API, creating the insertion order under the advertiser and
// campaign given.
$result = $this->service->advertisers_insertionOrders->create(
    advertiser-id,
    $insertionOrder
);

printf('Insertion Order %s was created.\n', $result['name']);

创建订单项

下面的示例展示了如何创建订单项

Java

// Create a line item object.
LineItem lineItem = new LineItem();
lineItem.setInsertionOrderId(insertion-order-id);
lineItem.setDisplayName(display-name);
lineItem.setLineItemType("LINE_ITEM_TYPE_DISPLAY_DEFAULT");
lineItem.setEntityStatus("ENTITY_STATUS_DRAFT");

// Create and set the line item flight.
LineItemFlight lineItemFlight = new LineItemFlight();
lineItemFlight
   .setFlightDateType("LINE_ITEM_FLIGHT_DATE_TYPE_INHERITED");
lineItem.setFlight(lineItemFlight);

// Create and set the line item budget.
LineItemBudget lineItemBudget = new LineItemBudget();
lineItemBudget
   .setBudgetAllocationType("LINE_ITEM_BUDGET_ALLOCATION_TYPE_FIXED");
lineItem.setBudget(lineItemBudget);

// Create and set the pacing setting.
Pacing pacing = new Pacing();
pacing.setPacingPeriod("PACING_PERIOD_DAILY");
pacing.setPacingType("PACING_TYPE_EVEN");
pacing.setDailyMaxMicros(10000L);
lineItem.setPacing(pacing);

// Create and set the frequency cap.
FrequencyCap frequencyCap = new FrequencyCap();
frequencyCap.setTimeUnit("TIME_UNIT_DAYS");
frequencyCap.setTimeUnitCount(1);
frequencyCap.setMaxImpressions(10);
lineItem.setFrequencyCap(frequencyCap);

// Create and set the partner revenue model.
PartnerRevenueModel partnerRevenueModel = new PartnerRevenueModel();
partnerRevenueModel
   .setMarkupType("PARTNER_REVENUE_MODEL_MARKUP_TYPE_CPM");
partnerRevenueModel.setMarkupAmount(10L);
lineItem.setPartnerRevenueModel(partnerRevenueModel);

// Set the list of IDs of the creatives associated with the line item.
lineItem.setCreativeIds(creative-ids);

// Create and set the bidding strategy.
BiddingStrategy biddingStrategy = new BiddingStrategy();
biddingStrategy
   .setFixedBid(new FixedBidStrategy().setBidAmountMicros(100000L));
lineItem.setBidStrategy(biddingStrategy);

// Configure the create request.
LineItems.Create request =
   service.advertisers().lineItems().create(advertiser-id, lineItem);

// Create the line item.
LineItem response = request.execute();

// Display the new line item.
System.out.printf("LineItem %s was created.", response.getName());

Python

# Create an line item object.
line_item_obj = {
    'insertionOrderId' : insertion-order-id,
    'displayName': display-name,
    'lineItemType': 'LINE_ITEM_TYPE_DISPLAY_DEFAULT',
    'entityStatus': 'ENTITY_STATUS_DRAFT',
    'flight': {
        'flightDateType': 'LINE_ITEM_FLIGHT_DATE_TYPE_INHERITED'
    },
    'budget': {
        'budgetAllocationType': 'LINE_ITEM_BUDGET_ALLOCATION_TYPE_FIXED'
    },
    'pacing': {
        'pacingPeriod': 'PACING_PERIOD_DAILY',
        'pacingType': 'PACING_TYPE_EVEN',
        'dailyMaxMicros': 10000
    },
    'frequencyCap': {
        'timeUnit': 'TIME_UNIT_DAYS',
        'timeUnitCount': 1,
        'maxImpressions': 10
    },
    'partnerRevenueModel': {
        'markupType': 'PARTNER_REVENUE_MODEL_MARKUP_TYPE_CPM',
        'markupAmount': 10
    },
    'creativeIds': creative-ids,
    'bidStrategy': {
        'fixedBid': {
            'bidAmountMicros': 100000
        }
    }
}

# Create the line item.
lineItem = service.advertisers().lineItems().create(
    advertiserId=advertiser-id,
    body=line_item_obj
).execute()

# Display the new line item.
print("Line Item %s was created." % lineItem["name"])

PHP

// Create a line item object.
$lineItem = new Google_Service_DisplayVideo_LineItem();
$lineItem->setInsertionOrderId(insertion-order-id);
$lineItem->setDisplayName(display-name);
$lineItem->setLineItemType('LINE_ITEM_TYPE_DISPLAY_DEFAULT');
$lineItem->setEntityStatus('ENTITY_STATUS_DRAFT');

// Create and set the line item flight.
$flight = new Google_Service_DisplayVideo_LineItemFlight();
$flight->setFlightDateType('LINE_ITEM_FLIGHT_DATE_TYPE_INHERITED');
$lineItem->setFlight($flight);

// Create and set the line item budget.
$budget = new Google_Service_DisplayVideo_LineItemBudget();
$budget->setBudgetAllocationType(
    'LINE_ITEM_BUDGET_ALLOCATION_TYPE_FIXED'
);
$lineItem->setBudget($budget);

// Create and set the pacing setting.
$pacing = new Google_Service_DisplayVideo_Pacing();
$pacing->setPacingPeriod('PACING_PERIOD_DAILY');
$pacing->setPacingType('PACING_TYPE_EVEN');
$pacing->setDailyMaxMicros(10000);
$lineItem->setPacing($pacing);

// Create and set the frequency cap.
$frequencyCap = new Google_Service_DisplayVideo_FrequencyCap();
$frequencyCap->setMaxImpressions(10);
$frequencyCap->setTimeUnit('TIME_UNIT_DAYS');
$frequencyCap->setTimeUnitCount(1);
$lineItem->setFrequencyCap($frequencyCap);

// Create and set the partner revenue model.
$partnerRevenueModel =
    new Google_Service_DisplayVideo_PartnerRevenueModel();
$partnerRevenueModel->setMarkupType(
    'PARTNER_REVENUE_MODEL_MARKUP_TYPE_CPM'
);
$partnerRevenueModel->setMarkupAmount(10);
$lineItem->setPartnerRevenueModel($partnerRevenueModel);

// Set the list of IDs of the creatives associated with the line item.
lineItem >setCreativeIds(creative-ids);

// Create and set the bidding strategy.
$biddingStrategy =  new Google_Service_DisplayVideo_BiddingStrategy();
$fixedBidStrategy = new Google_Service_DisplayVideo_FixedBidStrategy();
$fixedBidStrategy->setBidAmountMicros(100000);
$biddingStrategy->setFixedBid($fixedBidStrategy);
$lineItem->setBidStrategy($biddingStrategy);

// Create the line item.
$result = $this->service->advertisers_lineItems->create(
    advertiser-id,
    $lineItem
);

printf('Line Item %s was created.\n', $result['name']);

生成默认订单项

生成订单项时可使用由给定 LineItemType 确定的默认配置及其父级广告订单的现有配置。与创建标准 API 订单项不同,默认订单项在生成时会被分配与其父级广告订单相同的定位条件,这与界面中的操作类似。请使用广告订单 AssignedTargetingOptions 服务管理此设置

以下示例说明了如何生成默认订单项:

Java

// Create a default line item generation request.
GenerateDefaultLineItemRequest defaultLineItemRequest =
    new GenerateDefaultLineItemRequest();
defaultLineItemRequest.setInsertionOrderId(insertion-order-id);
defaultLineItemRequest.setDisplayName(display-name);
defaultLineItemRequest.setLineItemType("LINE_ITEM_TYPE_DISPLAY_DEFAULT");

// Configure the request.
LineItems.GenerateDefault request =
    service
        .advertisers()
        .lineItems()
        .generateDefault(advertiser-id, defaultLineItemRequest);

// Generate the default line item.
LineItem response = request.execute();

// Display the new line item.
System.out.printf("LineItem %s was created.", response.getName());

Python

# Create a default line item generation request.
default_li_request = {
    'insertionOrderId' : insertion-order-id,
    'displayName': display-name,
    'lineItemType': 'LINE_ITEM_TYPE_DISPLAY_DEFAULT'
}

# Generate the default line item.
line_item = service.advertisers().lineItems().generateDefault(
    advertiserId=advertiser-id,
    body=default_li_request
).execute()

# Display the new line item.
print("Line Item %s was created." % lineItem["name"])

PHP

// Create a default line item generation request.
$defaultLineItemRequest =
    new Google_Service_DisplayVideo_GenerateDefaultLineItemRequest();
$defaultLineItemRequest->setInsertionOrderId(insertion-order-id);
$defaultLineItemRequest->setDisplayName(display-name);
$defaultLineItemRequest->setLineItemType('LINE_ITEM_TYPE_DISPLAY_DEFAULT');

// Generate the default line item.
$result = $this->service->advertisers_lineItems->generateDefault(
    advertiser-id,
    $defaultLineItemRequest
);

// Display the new line item.
printf('Line Item %s was created.\n', $result['name']);

重复的订单项

您可以复制现有的订单项,从而生成一个新的订单项,其配置和定位设置与在同一广告订单下创建的现有订单项相同。

以下示例展示了如何复制现有订单项:

Java

// Create the duplicate line item request body.
DuplicateLineItemRequest requestBody = new DuplicateLineItemRequest();
requestBody.setTargetDisplayName(target-display-name);

// Configure the request.
LineItems.Duplicate request = service.advertisers().lineItems()
    .duplicate(advertiser-id, line-item-id, requestBody);

// Duplicate the line item.
DuplicateLineItemResponse response = request.execute();

// Display the line item ID of the new duplicate line item.
System.out.printf("A duplicate line item with the ID %s was created.",
    response.getDuplicateLineItemId());

Python

# Create the duplicate line item request body.
duplicate_request = {
    'targetDisplayName': target-display-name
}

# Duplicate the line item.
response = service.advertisers().lineItems().duplicate(
    advertiserId=advertiser-id,
    lineItemId=line-item-id,
    body=duplicate_request
).execute()

# Display the line item ID of the new duplicate line item.
print("A duplicate line item with the ID %s was created."
      % response["duplicateLineItemId"])

PHP

// Create the duplicate line item request body.
$requestBody = new Google_Service_DisplayVideo_DuplicateLineItemRequest();
$requestBody->setTargetDisplayName(target-display-name);

// Call the API, duplicating the line item.
$response = $service
    ->advertisers_lineItems
    ->duplicate(
        advertiser-id,
        line-item-id,
        $requestBody
    );

// Display the line item ID of the new duplicate line item.
printf(
    'A duplicate line item with the ID %s was created.',
    $response->getDuplicateLineItemId()
);