启用订单项

使用 Display & Video 360 API 创建的所有订单项最初均处于草稿状态。在此草稿状态下,订单项不会投放广告,因此您可以随意调整设置和定位条件,而这些更改不会影响任何当前的广告投放。本页介绍了您应执行哪些步骤来确认商品条目是否已准备好投放广告,以及如何将其状态更新为“有效”。

激活前的准备工作

订单项是通过广告购买和投放来支出广告收入的方式,因此请务必确保订单项在启用后会按预期投放广告。在启用订单项之前,请考虑以下事项:

  • 确保投放设置正确无误:检查订单项的 flight 字段,确保订单项的投放时间范围设置正确无误。订单项的投放时间范围可以是订单项的自定义时间范围,也可以由父级广告订单继承。
  • 验证订单项是否存在阻止其投放的警告:使用 advertisers.lineItems.get 检索订单项资源,然后检查 warningMessages 字段,以验证订单项是否存在可能会妨碍其投放的警告。LineItemWarningMessage 枚举会注明每个警告的影响。
  • 确认所有父级资源也处于有效状态:如果订单项的父级广告客户、广告系列或广告订单无效,则有效的订单项也不会开始投放广告。使用广告客户广告系列广告订单服务中的 GET 方法检索这些资源。

启用订单项

如需启用订单项,请将其 entityStatus 字段更新为 ENTITY_STATUS_ACTIVE。您可以使用 advertisers.lineItems.patch 方法更新单个订单项的此字段,也可以使用 advertisers.lineItems.bulkUpdate 更新给定广告客户中的多个订单项的此字段。

以下示例展示了如何使用 bulkUpdate 激活多个订单项:

Java

// Create the line item structure.
LineItem targetLineItem = new LineItem();
targetLineItem.setEntityStatus("ENTITY_STATUS_ACTIVE");

// Create the bulk update request body.
BulkUpdateLineItemsRequest requestBody = new BulkUpdateLineItemsRequest();
requestBody.setLineItemIds(line-item-ids);
requestBody.setTargetLineItem(targetLineItem);
requestBody.setUpdateMask("entityStatus");

// Configure the bulk update request.
LineItems.BulkUpdate request = service.advertisers().lineItems()
    .bulkUpdate(advertiser-id, requestBody);

// Update the line items.
BulkUpdateLineItemsResponse response = request.execute();

// Display the line items that were updated, failed, and skipped.
if (response.getUpdatedLineItemIds() != null) {
  System.out.printf(
      "The following line item IDs were successfully updated: %s.\n",
      Arrays.toString(response.getUpdatedLineItemIds().toArray()));
}
if (response.getFailedLineItemIds() != null) {
  System.out.printf("The following line item IDs failed to update: %s.\n",
      Arrays.toString(response.getFailedLineItemIds().toArray()));
  if (response.getErrors() != null) {
    System.out.printf(
        "The failed updates were caused by the following errors: %s.\n",
        Arrays.toString(response.getErrors().toArray()));
  }
}
if (response.getSkippedLineItemIds() != null) {
  System.out.printf(
      "The following line items IDs were skipped in the update: %s.\n",
      Arrays.toString(response.getSkippedLineItemIds().toArray()));
}

Python

# Create a line item object with only updated entity status.
line_item_obj = {
    'entityStatus': 'ENTITY_STATUS_ACTIVE'
}

# Build the bulk update request.
bulk_update_request = {
    'lineItemIds': line-item-ids,
    'targetLineItem': line_item_obj,
    'updateMask': "entityStatus"
}

# Update the line items.
response = service.advertisers().lineItems().bulkUpdate(
    advertiserId=advertiser-id,
    body=bulk_update_request
).execute()

# Display the line items that were updated, failed, and skipped.
if 'updatedLineItemIds' in response:
  print("The following line item IDs were updated: %s"
        % response['updatedLineItemIds'])
if 'failedLineItemIds' in response:
  print("The following line item IDs failed to update: %s"
        % response['failedLineItemIds'])
  if 'errors' in response:
    print("The failed updates were caused by the following errors:")
    for error in response["errors"]:
      print("Error code: %s, Message: %s" % (error["code"], error["message"]))
if 'skippedLineItemIds' in response:
  print("The following line items IDs were skipped in the update:: %s"
        % response['skippedLineItemIds'])

PHP

// Create request body.
$body = new Google_Service_DisplayVideo_BulkUpdateLineItemsRequest();
$body->setLineItemIds(line-item-ids);

// Create target line item with updated fields.
$lineItem = new Google_Service_DisplayVideo_LineItem();
$lineItem->setEntityStatus('ENTITY_STATUS_ACTIVE');
$body->setTargetLineItem($lineItem);

// Set update mask in request body.
$body->setUpdateMask("entityStatus");

// Call the API, updating the entity status for the identified line item.
$response = $service->advertisers_lineItems->bulkUpdate(
    advertiser-id,
    $body
);

// Display the line items that were updated, failed, and skipped.
if (!empty($response->getUpdatedLineItemIds())) {
    printf('The following line item IDs were updated:\n');
    foreach ($response->getUpdatedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
}
if (!empty($response->getFailedLineItemIds())) {
    print('The following line item IDs failed to update:\n');
    foreach ($response->getFailedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
    if (!empty($response->getErrors())) {
        print('The failed updates were caused by the following errors:\n');
        foreach ($response->getErrors() as $error) {
            printf(
                'Error Code: %s, Message: %s\n',
                $error->getCode(),
                $error->getMessage()
            );
        }
    }
}
if (!empty($response->getSkippedLineItemIds())) {
    print('The following line item IDs were skipped in the update:\n');
    foreach ($response->getSkippedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
}