Đặt tiêu chí nhắm mục tiêu

Các dịch vụ Tuỳ chọn nhắm mục tiêu, Tuỳ chọn nhắm mục tiêu được chỉ địnhMục hàng đều được sử dụng cùng nhau để đặt tiêu chí nhắm mục tiêu mục hàng trong API Display & Video 360. Trang này mô tả và đưa ra ví dụ về cách tìm các tuỳ chọn nhắm mục tiêu hiện có, chỉ định các tuỳ chọn nhắm mục tiêu cho mục hàng và thực thi các thao tác hàng loạt trên mục hàng để liệt kê và chỉnh sửa các tuỳ chọn nhắm mục tiêu đã chỉ định.

Tìm các tiêu chí nhắm mục tiêu có thể sử dụng

Các tuỳ chọn nhắm mục tiêu sử dụng các biến do người dùng chỉ định, các thực thể có thể nhắm mục tiêu hiện có hoặc các tuỳ chọn có sẵn để xác định đối tượng mục tiêu mong muốn. Các tuỳ chọn có sẵn được xác định bằng cách sử dụng giá trị enum hoặc mã tuỳ chọn nhắm mục tiêu, tuỳ thuộc vào loại tiêu chí nhắm mục tiêu. Các thực thể có thể nhắm mục tiêu được xác định bằng mã nhận dạng thực thể. Bạn có thể tìm thấy mã tuỳ chọn nhắm mục tiêu và mã thực thể bằng cách sử dụng API Display & Video 360.

Sử dụng các giá trị enum đã đặt

Các lựa chọn nhắm mục tiêu cho các loại tiêu chí nhắm mục tiêu sau đây được chỉ định bằng cách sử dụng các loại enum cụ thể:

TargetingType Enum
TARGETING_TYPE_AGE_RANGE AgeRange
TARGETING_TYPE_CONTENT_INSTREAM_POSITION ContentInstreamPosition
TARGETING_TYPE_CONTENT_OUTSTREAM_POSITION ContentOutstreamPosition
TARGETING_TYPE_DEVICE_TYPE DeviceType
TARGETING_TYPE_DIGITAL_CONTENT_LABEL_EXCLUSION ContentRatingTier
TARGETING_TYPE_ENVIRONMENT Environment
TARGETING_TYPE_EXCHANGE Exchange
TARGETING_TYPE_GENDER Gender
TARGETING_TYPE_HOUSEHOLD_INCOME HouseholdIncome
TARGETING_TYPE_NATIVE_CONTENT_POSITION NativeContentPosition
TARGETING_TYPE_OMID Omid
TARGETING_TYPE_PARENTAL_STATUS ParentalStatus
TARGETING_TYPE_SENSITIVE_CATEGORY_EXCLUSION SensitiveCategory
TARGETING_TYPE_VIDEO_PLAYER_SIZE VideoPlayerSize
TARGETING_TYPE_VIEWABILITY Viewability

Bạn có thể sử dụng phiên bản chuỗi của giá trị enum có liên quan để xác định các tài nguyên AssignedTargetingOption hiện có của các loại tiêu chí nhắm mục tiêu này và có sẵn trong trường assignedTargetingOptionIdAlias. Bạn có thể sử dụng giá trị bí danh này thay cho assignedTargetingOptionId khi truy xuất hoặc xoá các tuỳ chọn nhắm mục tiêu đã chỉ định.

Truy xuất mã tuỳ chọn nhắm mục tiêu

Các loại tiêu chí nhắm mục tiêu sử dụng các tuỳ chọn có sẵn được chỉ định bằng cách sử dụng mã tuỳ chọn nhắm mục tiêu tương ứng.

Ví dụ: có một số lượng hữu hạn vị trí trên màn hình có thể được nhắm mục tiêu bằng cách sử dụng loại tiêu chí nhắm mục tiêu TARGETING_TYPE_ON_SCREEN_POSITION. Mỗi vị trí này đều có một mã lựa chọn nhắm mục tiêu tương ứng.

Bạn có thể truy xuất các mã tuỳ chọn nhắm mục tiêu này thông qua dịch vụ Tuỳ chọn nhắm mục tiêu. Tuỳ thuộc vào loại tiêu chí nhắm mục tiêu, quá trình truy xuất sẽ được thực hiện theo một trong hai cách:

  • Truy xuất riêng lẻ hoặc danh sách đầy đủ: Bạn có thể truy xuất các tuỳ chọn cho hầu hết các loại tiêu chí nhắm mục tiêu bằng cách sử dụng các phương thức getlist. Sử dụng targetingTypes.targetingOptions.get để truy xuất thông tin chi tiết về một tuỳ chọn nhắm mục tiêu được xác định bằng loại tiêu chí nhắm mục tiêu và mã tuỳ chọn nhắm mục tiêu. Sử dụng targetingTypes.targetingOptions.list để liệt kê tất cả các lựa chọn nhắm mục tiêu có sẵn của một loại nhắm mục tiêu nhất định.
  • Tìm kiếm: Bạn phải truy xuất các tuỳ chọn cho loại nhắm mục tiêu dựa trên vị trí (TARGETING_TYPE_GEO_REGION, TARGETING_TYPE_POITARGETING_TYPE_BUSINESS_CHAIN) bằng phương thức search. Sử dụng targetingTypes.targetingOptions.search để truy xuất các tuỳ chọn nhắm mục tiêu của một loại nhất định khớp với các chuỗi truy vấn nhất định.

Sau đây là ví dụ về cách truy xuất danh sách các tuỳ chọn nhắm mục tiêu có thể dùng cho loại nhắm mục tiêu TARGETING_TYPE_BROWSER:

Java

// Configure the list request.
TargetingOptions.List request =
   service
       .targetingTypes()
       .targetingOptions()
       .list("TARGETING_TYPE_BROWSER")
       .setAdvertiserId(advertiser-id);

// Create the response and nextPageToken variables.
ListTargetingOptionsResponse response;
String nextPageToken = null;

do {
 // Create and execute the list request.
 response = request.setPageToken(nextPageToken).execute();

 // Check if the response is empty.
 if (response.isEmpty()) {
   System.out.print("List request returned no Targeting Options");
   break;
 }

 // Iterate over retrieved targeting options.
 for (TargetingOption option : response.getTargetingOptions()) {
   System.out.printf(
       "Targeting Option ID: %s, Browser Display Name: '%s'\n",
       option.getTargetingOptionId(), option.getBrowserDetails().getDisplayName());
 }

 // Update the next page token.
 nextPageToken = response.getNextPageToken();
} while (!Strings.isNullOrEmpty(nextPageToken));

Python

# Create the page token variable.
next_page_token = ""

while True:
  # Request the targeting options list.
  response = service.targetingTypes() \
    .targetingOptions().list(
      advertiserId=advertiser-id,
      targetingType="TARGETING_TYPE_BROWSER",
      pageToken=next_page_token
  ).execute()

  # Check if response is empty.
  if not response:
    print("List request returned no Targeting Options")
    break

  # Iterate over retrieved targeting options.
  for option in response['targetingOptions']:
    print("Targeting Option ID: %s, Browser Display Name: %s"
          % (option['targetingOptionId'], option['browserDetails']['displayName']))

  # Break out of loop if there is no next page.
  if 'nextPageToken' not in response:
    break

  # Update the next page token.
  next_page_token = response['nextPageToken']

PHP

// Create the page token variable.
$nextPageToken = null;

do {
    // Build the query parameters object for the request.
    $optParams = array(
        'advertiserId' => advertiser-id,
        'pageToken' => $nextPageToken
    );

    // Call the API, getting the browser targeting options for the
    // identified advertiser.
    $response = $this
        ->service
        ->targetingTypes_targetingOptions
        ->listTargetingTypesTargetingOptions(
            'TARGETING_TYPE_BROWSER',
            $optParams
        );

    // Print the resulting targeting options.
    if (!empty($response->getTargetingOptions())) {
        foreach ($response->getTargetingOptions() as $option) {
            printf(
                'Targeting Option ID: %s, Browser Display Name: %s\n',
                $option['targetingOptionId'],
                $option['browserDetails']['displayName']
            );
        }
    } else {
        print('No targeting options returned\n');
    }

    // Update the next page token.
    $nextPageToken = $response->getNextPageToken();
} while (
    !empty($response->getTargetingOptions())
    && $nextPageToken
);

Liệt kê các thực thể có thể nhắm mục tiêu

Để nhắm mục tiêu một mục hàng bằng một thực thể có thể nhắm mục tiêu hiện có, bạn cần có mã nhận dạng của thực thể đó. Bạn có thể truy xuất các thực thể có thể nhắm mục tiêu, chẳng hạn như kênh, đối tượng kết hợpnhóm nguồn khoảng không quảng cáo thông qua các dịch vụ của chính chúng trong API Display & Video 360.

Mỗi dịch vụ có phương thức getlist riêng. Sử dụng phương thức get để xác nhận rằng một thực thể có sẵn trong một nhà quảng cáo nhất định. Sử dụng phương thức list để khám phá tất cả các thực thể thuộc loại tài nguyên đó mà một nhà quảng cáo nhất định có thể sử dụng, do đó, có thể được dùng để chỉ định tiêu chí nhắm mục tiêu cho một mục hàng trong nhà quảng cáo đó.

Bạn cũng có thể quản lý một tập hợp con các thực thể có thể nhắm mục tiêu thông qua API. Việc này được thực hiện thông qua các phương thức createpatch trong dịch vụ tương ứng, cũng như các dịch vụ cho từng giá trị được liệt kê trong các thực thể, chẳng hạn như nguồn khoảng không quảng cáo, từ khoá phủ địnhvị trí.

Tạo mã tuỳ chọn nhắm mục tiêu theo địa điểm yêu thích

Bạn có thể truy xuất các tuỳ chọn nhắm mục tiêu địa điểm yêu thích được đặt tên trong TARGETING_TYPE_POI bằng cách sử dụng targetingTypes.targetingOptions.search. Ngoài ra, bạn có thể tạo mã nhận dạng tuỳ chỉnh cho tuỳ chọn nhắm mục tiêu TARGETING_TYPE_POI để nhắm đến các toạ độ vĩ độ-kinh độ cụ thể.

Hãy làm theo các bước sau để tạo mã tuỳ chọn nhắm mục tiêu theo địa điểm yêu thích:

  1. Truy xuất toạ độ vĩ độ-kinh độ (ví dụ: "40.7414691, -74.003387")
  2. Làm tròn giá trị toạ độ đến vị trí thập phân thứ sáu (ví dụ: "40.741469, -74.003387")
  3. Xoá dấu phẩy động khỏi các giá trị toạ độ (ví dụ: "40741469, -74003387")
  4. Dùng toán tử nối để nối hai giá trị này thành một chuỗi, phân tách bằng dấu chấm phẩy (ví dụ: "40741469;-74003387")

Chuỗi thu được có thể được dùng làm targetingOptionId khi tạo một tuỳ chọn nhắm mục tiêu được chỉ định TARGETING_TYPE_POI.

Sau khi tạo, các trường targetingOptionIdassignedTargetingOptionId của tài nguyên tuỳ chọn nhắm mục tiêu được chỉ định sẽ được cập nhật, thêm dấu chấm phẩy và hàm băm chữ và số.

Chỉ định một tuỳ chọn nhắm mục tiêu

Tiêu chí nhắm mục tiêu được chỉ định cho một mục hàng được biểu thị dưới dạng Tuỳ chọn nhắm mục tiêu được chỉ định. Bạn có thể quản lý các thực thể này bằng cách sử dụng dịch vụ Tuỳ chọn nhắm mục tiêu được chỉ định. Việc tạo một tuỳ chọn nhắm mục tiêu được chỉ định sẽ áp dụng các thông tin nhắm mục tiêu đó cho mục hàng mẹ. Việc xoá một tuỳ chọn nhắm mục tiêu đã chỉ định hiện có sẽ xoá tiêu chí nhắm mục tiêu đó.

Sử dụng advertisers.lineItems.targetingTypes.assignedTargetingOptions.create để tạo các tuỳ chọn nhắm mục tiêu được chỉ định. Chỉ định các thông số nhắm mục tiêu trong trường details của tài nguyên tuỳ chọn nhắm mục tiêu được chỉ định tương ứng với loại nhắm mục tiêu dự kiến.

Sau đây là ví dụ về cách tạo một tuỳ chọn nhắm mục tiêu được chỉ định thuộc loại nhắm mục tiêu TARGETING_TYPE_BROWSER:

Java

// Create an AssignedTargetingOption object of the
// browser targeting type.
AssignedTargetingOption assignedTargetingOption =
   new AssignedTargetingOption()
       .setBrowserDetails(
           new BrowserAssignedTargetingOptionDetails()
               .setTargetingOptionId(targeting-option-id));

// Configure the create request.
AssignedTargetingOptions.Create request =
   service
       .advertisers()
       .lineItems()
       .targetingTypes()
       .assignedTargetingOptions()
       .create(
           advertiser-id,
           line-item-id,
           "TARGETING_TYPE_BROWSER",
           assignedTargetingOption);

// Send the request.
AssignedTargetingOption response = request.execute();

// Display the new assigned targeting option.
System.out.printf("AssignedTargetingOption %s was created.",
   response.getName());

Python

# Create a assigned targeting option object.
assigned_targeting_option_obj = {
    'browserDetails': {
        'targetingOptionId': targeting-option-id
    }
}

# Create the assigned targeting option.
assigned_targeting_option = service.advertisers().lineItems()\
  .targetingTypes().assignedTargetingOptions().create(
    advertiserId=advertiser-id,
    lineItemId=line-item-id,
    targetingType="TARGETING_TYPE_BROWSER",
    body=assigned_targeting_option_obj
).execute()

# Display the new assigned targeting option.
print("Assigned Targeting Option %s was created."
      % assigned_targeting_option["name"])

PHP

// Create a assigned targeting option object.
$assignedTargetingOption =
    new Google_Service_DisplayVideo_AssignedTargetingOption();

// Create and set browser details.
$details =
    new Google_Service_DisplayVideo_BrowserAssignedTargetingOptionDetails();
$details->setTargetingOptionId(targeting-option-id);
$assignedTargetingOption->setBrowserDetails($details);

// Call the API, creating the browser assigned targeting option for the
// given line item.
$result = $this
    ->service
    ->advertisers_lineItems_targetingTypes_assignedTargetingOptions
    ->create(
        advertiser-id,
        line-item-id,
        'TARGETING_TYPE_BROWSER',
        $assignedTargetingOption
    );

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

Lỗi

Lỗi cấu hình nhắm mục tiêu

Có một số quy tắc phức tạp liên quan đến tiêu chí nhắm mục tiêu trong Display & Video 360. Các quy tắc này được thực thi trong API Display & Video 360 thông qua các lỗi được trả về khi tạo tuỳ chọn nhắm mục tiêu được chỉ định. Lỗi do API trả về sẽ chỉ định lỗi vi phạm.

Lỗi chủ yếu là do tiêu chí nhắm mục tiêu hiện tại được chỉ định cho một mục hàng. Sử dụng advertisers.lineItems.targetingTypes.assignedTargetingOptions.list để truy xuất tất cả các lựa chọn nhắm mục tiêu của một loại tiêu chí nhắm mục tiêu nhất định được chỉ định cho một mục hàng, đánh giá xem liệu có thể nhắm mục tiêu mong muốn hay không trong phạm vi giới hạn, đồng thời sử dụng advertisers.lineItems.targetingTypes.assignedTargetingOptions.delete để xoá mọi tiêu chí nhắm mục tiêu không mong muốn trước khi thử tạo lại lựa chọn tiêu chí nhắm mục tiêu được chỉ định mong muốn.

Lỗi nhắm mục tiêu theo YouTube và đối tác

Bạn không thể cập nhật tiêu chí nhắm mục tiêu dành riêng cho chiến dịch YouTube và Đối tác bằng API Display & Video 360. Nếu cố gắng làm như vậy, bạn sẽ gặp lỗi.

Tiêu chí nhắm mục tiêu YouTube và đối tác bao gồm tất cả tiêu chí nhắm mục tiêu được chỉ định trực tiếp cho Mục hàng YouTube và đối tác và Nhóm quảng cáo, cũng như mọi tiêu chí nhắm mục tiêu thuộc các loại tiêu chí nhắm mục tiêu sau:

  • TARGETING_TYPE_SESSION_POSITION
  • TARGETING_TYPE_YOUTUBE_CHANNEL
  • TARGETING_TYPE_YOUTUBE_VIDEO

Lỗi đồng thời

Việc cố gắng cập nhật chế độ cài đặt hoặc tiêu chí nhắm mục tiêu của một mục hàng thông qua nhiều yêu cầu đồng thời sẽ dẫn đến lỗi.

Nếu cần thêm hoặc xoá nhiều lựa chọn nhắm mục tiêu được chỉ định cho một mục hàng cùng một lúc, bạn nên sử dụng yêu cầu chỉnh sửa hàng loạt. Nếu bạn muốn cập nhật chế độ cài đặt và tiêu chí nhắm mục tiêu của một mục hàng, hãy tạo yêu cầu advertisers.lineItems.patch và yêu cầu nhắm mục tiêu có liên quan liên tiếp để đảm bảo yêu cầu thứ hai không được gửi cho đến khi yêu cầu đầu tiên trả về phản hồi.

Thao tác nhắm mục tiêu hàng loạt và trên toàn tài nguyên

Bạn có thể sử dụng phương pháp nhắm mục tiêu hàng loạttrên toàn tài nguyên để quản lý các tuỳ chọn nhắm mục tiêu được chỉ định trên các loại nhắm mục tiêu:

  • Sử dụng các phương pháp nhắm mục tiêu hàng loạt để truy xuất hoặc chỉnh sửa các lựa chọn nhắm mục tiêu trên nhiều loại tiêu chí nhắm mục tiêu và trong nhiều tài nguyên. Bạn có thể truy xuất cấu hình nhắm mục tiêu đầy đủ của nhiều mục hàng bằng cách sử dụng advertisers.lineItems.bulkListAssignedTargetingOptions hoặc cập nhật giống nhau cho tiêu chí nhắm mục tiêu trên nhiều mục hàng bằng cách sử dụng advertisers.lineItems.bulkEditAssignedTargetingOptions. Các tính năng này chỉ có trong dịch vụ advertisers.lineItems.
  • Sử dụng Phương pháp nhắm mục tiêu trên toàn tài nguyên để truy xuất hoặc chỉnh sửa các lựa chọn nhắm mục tiêu trên nhiều loại tiêu chí nhắm mục tiêu trong một tài nguyên. Các dịch vụ này có trong dịch vụ partnersadvertisers và được đặt tên là listAssignedTargetingOptions hoặc editAssignedTargetingOptions.

Nếu bạn muốn xem toàn bộ tiêu chí nhắm mục tiêu hiện tại của một mục hàng, muốn áp dụng cấu hình nhắm mục tiêu đặt trước cho một mục hàng hoặc cần thực hiện nhiều thay đổi đối với tiêu chí nhắm mục tiêu của một mục hàng cùng một lúc, hãy cân nhắc sử dụng các phương thức nhắm mục tiêu này.

Nhắm mục tiêu theo trang thông tin hàng loạt

advertisers.lineItems.bulkListAssignedTargetingOptions cung cấp một cách để xem tất cả tiêu chí nhắm mục tiêu được chỉ định cho một hoặc nhiều mục hàng trên nhiều loại tiêu chí nhắm mục tiêu. Phương thức này hoạt động tương tự như mọi phương thức list khác. Bạn có thể sử dụng tham số truy vấn filter để lọc kết quả theo TargetingType hoặc Inheritance.

Dưới đây là ví dụ về cách liệt kê tất cả các lựa chọn nhắm mục tiêu được chỉ định cho một mục hàng mà đối tác hoặc nhà quảng cáo mẹ kế thừa:

Java

// Configure the bulk list request.
LineItems.BulkListAssignedTargetingOptions request =
    service.advertisers().lineItems()
        .bulkListAssignedTargetingOptions(advertiser-id);

// Set Line Items to retrieve targeting for.
request.setLineItemIds(line-item-ids);

// Set filter to only return inherited assigned targeting options.
request.setFilter(
    "inheritance=\"INHERITED_FROM_ADVERTISER\" OR inheritance=\"INHERITED_FROM_PARTNER\"");

// Create the response and nextPageToken variables.
BulkListAssignedTargetingOptionsResponse response;
String nextPageToken = null;

do {
  // Set page token and execute the list request.
  response = request.setPageToken(nextPageToken).execute();

  // Check if the response is empty.
  if (response.isEmpty()) {
    System.out.print("Bulk list request returned no Assigned Targeting Options");
    break;
  }

  // Iterate over retrieved line item assigned targeting option wrapper objects.
  for (LineItemAssignedTargetingOption lineItemAssignedTargetingOption
      : response.getLineItemAssignedTargetingOptions()) {
    System.out.printf(
        "Assigned Targeting Option %s found\n",
        lineItemAssignedTargetingOption.getAssignedTargetingOption().getName());
  }

  // Update the next page token.
  nextPageToken = response.getNextPageToken();
} while (!Strings.isNullOrEmpty(nextPageToken));

Python

# Create the page token variable.
next_page_token = ""

while True:
  # Execute the list request.
  response = service.advertisers().lineItems() \
    .bulkListAssignedTargetingOptions(
      advertiserId=advertiser-id,
      lineItemIds=line-item-ids,
      filter="inheritance=\"INHERITED_FROM_ADVERTISER\" OR "
             "inheritance=\"INHERITED_FROM_PARTNER\"",
      pageToken=next_page_token
  ).execute()

  # Check if response is empty.
  if not response:
    print("Bulk list request returned no Assigned Targeting Options")
    break

  # Iterate over retrieved assigned targeting options.
  for lineItemAssignedTargetingOption in response['lineItemAssignedTargetingOptions']:
    print("Assigned Targeting Option %s found"
          % (lineItemAssignedTargetingOption['assignedTargetingOption']['name']))

  # Break out of loop if there is no next page.
  if 'nextPageToken' not in response:
    break

  # Update the next page token.
  next_page_token = response['nextPageToken']

PHP

// Create the page token variable.
$nextPageToken = null;

do {
    // Build the query parameters object for the request.
    $optParams = array(
        'lineItemIds' => line-item-ids,
        'filter' => "inheritance=\"INHERITED_FROM_ADVERTISER\" OR "
            . "inheritance=\"INHERITED_FROM_PARTNER\"",
        'pageToken' => $nextPageToken
    );

    // Call the API, getting all the assigned targeting options for the
    // identified line item.
    $response = $service
        ->advertisers_lineItems
        ->bulkListAssignedTargetingOptions(
            advertiser-id,
            $optParams
    );

    // Print the returned assigned targeting options.
    if (!empty($response->getLineItemAssignedTargetingOptions())) {
        foreach ($response->getLineItemAssignedTargetingOptions() as $option) {
            printf('Assigned Targeting Option %s found\n', $option->getAssignedTargetingOption()['name']);
        }
    } else {
        print('No targeting options returned\n');
    }

    // Update the next page token.
    $nextPageToken = $response->getNextPageToken();
} while (
    !empty($response->getLineItemAssignedTargetingOptions())
    && $nextPageToken);

Chỉnh sửa tiêu chí nhắm mục tiêu theo số lượng lớn

advertisers.lineItems.bulkEditAssignedTargetingOptions cung cấp cách thêm và xoá nhiều tuỳ chọn nhắm mục tiêu của nhiều loại nhắm mục tiêu khỏi một hoặc nhiều mục hàng cùng một lúc.

Phương thức này sẽ lấy danh sách DeleteAssignedTargetingOptionsRequests và danh sách CreateAssignedTargetingOptionsRequests. Một đối tượng yêu cầu duy nhất có thể đại diện cho việc xoá hoặc tạo nhiều tuỳ chọn nhắm mục tiêu được chỉ định thuộc cùng một loại nhắm mục tiêu.

Nếu việc xoá hoặc tạo một tuỳ chọn nhắm mục tiêu đã chỉ định gây ra lỗi cho một mục hàng, thì thao tác hàng loạt sẽ bị huỷ đối với mục hàng đó. Yêu cầu này sẽ trả về danh sách các mục hàng đã cập nhật thành công, cũng như danh sách các mục hàng không cập nhật đượccác lỗi liên quan.

Dưới đây là ví dụ về cách chỉnh sửa hàng loạt các lựa chọn nhắm mục tiêu được chỉ định cho một hoặc nhiều mục hàng, trong đó có danh sách các lựa chọn nhắm mục tiêu được chỉ định cần xoá và các lựa chọn nhắm mục tiêu cần tạo:

Java

// Create a bulk edit request.
BulkEditAssignedTargetingOptionsRequest requestContent =
    new BulkEditAssignedTargetingOptionsRequest();

// Set line item IDs in edit request.
requestContent.setLineItemIds(line-item-ids);

// Build delete request list.
ArrayList<DeleteAssignedTargetingOptionsRequest> deleteRequests =
    new ArrayList<DeleteAssignedTargetingOptionsRequest>();

// Add browser assigned targeting option IDs to delete request list.
deleteRequests.add(new DeleteAssignedTargetingOptionsRequest()
    .setTargetingType("TARGETING_TYPE_BROWSER")
    .setAssignedTargetingOptionIds(delete-browser-assigned-targeting-ids));

// Add device make or model assigned targeting option IDs to delete request list.
deleteRequests.add(new DeleteAssignedTargetingOptionsRequest()
    .setTargetingType("TARGETING_TYPE_DEVICE_MAKE_MODEL")
    .setAssignedTargetingOptionIds(
        delete-device-make-model-assigned-targeting-ids));

// Set delete requests in edit request.
requestContent.setDeleteRequests(deleteRequests);

// Build create request list.
ArrayList<CreateAssignedTargetingOptionsRequest> createRequests =
    new ArrayList<CreateAssignedTargetingOptionsRequest>();

// Create browser assigned targeting option create request.
CreateAssignedTargetingOptionsRequest createBrowserTargetingRequest =
    new CreateAssignedTargetingOptionsRequest();
createBrowserTargetingRequest.setTargetingType("TARGETING_TYPE_BROWSER");

// Create and set list of browser assigned targeting options.
ArrayList<AssignedTargetingOption> createBrowserAssignedTargetingOptions =
    new ArrayList<AssignedTargetingOption>();
for (String targetingOptionId : create-browser-assigned-targeting-ids) {
  createBrowserAssignedTargetingOptions.add(new AssignedTargetingOption()
      .setBrowserDetails(
          new BrowserAssignedTargetingOptionDetails()
              .setTargetingOptionId(targetingOptionId)));
}
createBrowserTargetingRequest
    .setAssignedTargetingOptions(createBrowserAssignedTargetingOptions);

// Add browser assigned targeting options to list of create requests.
createRequests.add(createBrowserTargetingRequest);

// Set create requests in edit request.
requestContent.setCreateRequests(createRequests);

// Configure the bulk edit request.
LineItems.BulkEditAssignedTargetingOptions request =
    service.advertisers().lineItems()
        .bulkEditAssignedTargetingOptions(
            advertiser-id,
            requestContent);

// Execute bulk edit request.
BulkEditAssignedTargetingOptionsResponse response = request.execute();

// Check if any line items updated successfully.
if (response.getUpdatedLineItemIds() == null || response.getUpdatedLineItemIds().isEmpty()) {
  System.out.println("No line items were updated successfully.");
} else {
  System.out.printf(
      "Targeting configurations for the following line item IDs were updated: %s.\n",
      Arrays.toString(response.getUpdatedLineItemIds().toArray()));
}

// Check if any line items failed to update.
if (response.getFailedLineItemIds() == null || response.getFailedLineItemIds().isEmpty()) {
  System.out.println("No line items failed to update.");
} else {
  // Print the line items that failed to update.
  System.out.printf(
      "Targeting configurations for the following line item IDs failed to update: %s.\n",
      Arrays.toString(response.getFailedLineItemIds().toArray()));

  // Print errors thrown for failed updates.
  System.out.println("The failed updates were caused by the following errors:");
  for (Status error : response.getErrors()) {
    System.out.printf("Error Code: %s, Message: %s\n", error.getCode(), error.getMessage());
  }
}

Python

# Build assigned targeting option objects to create.
createBrowserAssignedTargetingOptions = []
for targeting_id in create-browser-assigned-targeting-ids:
  createBrowserAssignedTargetingOptions.append(
      {'browserDetails': {'targetingOptionId': targeting_id}}
  )

# Create a bulk edit request.
bulk_edit_line_item_request = {
    'lineItemIds': line-item-ids,
    'deleteRequests': [
        {
            'targetingType': 'TARGETING_TYPE_BROWSER',
            'assignedTargetingOptionIds':
              delete-browser-assigned-targeting-ids
        },
        {
            'targetingType': 'TARGETING_TYPE_DEVICE_MAKE_MODEL',
            'assignedTargetingOptionIds':
              delete-device-make-model-assigned-targeting-ids
        }
    ],
    'createRequests': [
        {
            'targetingType': 'TARGETING_TYPE_BROWSER',
            'assignedTargetingOptions':
              createBrowserAssignedTargetingOptions
        }
    ]
}

# Edit the line item targeting.
response = service.advertisers().lineItems()\
  .bulkEditAssignedTargetingOptions(
    advertiserId=advertiser-id,
    body=bulk_edit_line_item_request
).execute()

# Print successfully updated line items.
if 'updatedLineItemIds' not in response:
  print("No line items were updated successfully.")
else:
  print("Targeting configurations for the following line item IDs were updated: %s"
        % response['updatedLineItemIds'])

# Print line items that failed to update.
if 'failedLineItemIds' not in response:
  print("No line items failed to update.")
else:
  print("Targeting configurations for 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"]))

PHP

// Create delete request list.
$deleteRequests = array();

// Create and add browser assigned targeting option IDs to delete request list.
$deleteBrowserTargetingRequest =
    new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest();
$deleteBrowserTargetingRequest->setTargetingType(
    "TARGETING_TYPE_BROWSER"
);
$deleteBrowserTargetingRequest->setAssignedTargetingOptionIds(
    delete-browser-assigned-targeting-ids
);
$deleteRequests[] = $deleteBrowserTargetingRequest;

// Create and add device assigned targeting option IDs to delete request list.
$deleteDeviceTargetingRequest =
    new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest();
$deleteDeviceTargetingRequest->setTargetingType(
    "TARGETING_TYPE_DEVICE_MAKE_MODEL"
);
$deleteDeviceTargetingRequest->setAssignedTargetingOptionIds(
    delete-device-make-model-assigned-targeting-ids
);
$deleteRequests[] = $deleteDeviceTargetingRequest;

// Create create request list.
$createRequests = array();

// Create and populate list of browser assigned targetion options to create.
$createBrowserAssignedTargetingOptions = array();
foreach (create-browser-assigned-targeting-ids as $optionId) {
    $option = new Google_Service_DisplayVideo_AssignedTargetingOption();
    $details =
        new Google_Service_DisplayVideo_BrowserAssignedTargetingOptionDetails();
    $details->setTargetingOptionId($optionId);

    $option->setBrowserDetails($details);
    $createBrowserAssignedTargetingOptions[] = $option;
}

// Create and add browser assigned targeting option create request to create
// request list.
$createBrowserTargetingRequest =
    new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest();
$createBrowserTargetingRequest->setTargetingType(
    "TARGETING_TYPE_BROWSER"
);
$createBrowserTargetingRequest->setAssignedTargetingOptions(
    $createBrowserAssignedTargetingOptions
);
$createRequests[] = $createBrowserTargetingRequest;

// Create a bulk edit request and assign create and delete request lists.
$body =
    new Google_Service_DisplayVideo_BulkEditAssignedTargetingOptionsRequest();
$body->setLineItemIds(line-item-ids);
$body->setCreateRequests($createRequests);
$body->setDeleteRequests($deleteRequests);

// Call the API, editing the assigned targeting options for the identified
// line item.
$response = $service
    ->advertisers_lineItems
    ->bulkEditAssignedTargetingOptions(
        advertiser-id,
        $body
    );

// Print successfully updated line items.
if (!empty($response->getUpdatedLineItemIds())) {
    printf('Targeting configurations for the following line item IDs were updated:\n');
    foreach ($response->getUpdatedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
} else {
    print('No line items were updated successfully.\n');
}

// Print line items that failed to update.
if (!empty($response->getFailedLineItemIds())) {
    print('Targeting configurations for the following line item IDs failed to update:\n');
    foreach ($response->getFailedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
    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());
    }
} else {
    print('No line items failed to update.\n');
}