Các phương pháp thay thế để tạo tài nguyên

Display & Video 360 API cung cấp các phương thức thay thế để tạo mục hàng. Các phương thức này cho phép bạn áp dụng chế độ cài đặt của các tài nguyên hiện có cho các mục hàng mới.

Tạo bản sao của các mục hàng hiện có

duplicate sao chép một mục hàng trong cùng một đơn đặt hàng chèn. Phương thức này tạo ra một mục hàng mới có cùng chế độ cài đặt và tiêu chí nhắm mục tiêu như mục hàng hiện có.

Sau đây là cách sao chép một mục hàng:

Java

// Provide the ID of the parent advertiser.
long advertiserId = advertiser-id;

// Provide the ID of the existing line item to duplicate.
long existingLineItemId = existing-line-item-id;

// Provide the display name of the line item to generate.
String displayName = display-name;

// Provide whether the line item will serve EU political ads.
String containsEuPoliticalAds = contains-eu-political-ads;

// Create the duplicate line item request structure.
DuplicateLineItemRequest duplicateLineItemRequest =
    new DuplicateLineItemRequest()
        .setTargetDisplayName(displayName)
        .setContainsEuPoliticalAds(containsEuPoliticalAds);

// Execute the request to generate the line item.
DuplicateLineItemResponse response =
    service
        .advertisers()
        .lineItems()
        .duplicate(advertiserId, existingLineItemId, duplicateLineItemRequest)
        .execute();

// Display the new line item ID.
System.out.printf(
    "Line Item ID %s was duplicated to create line item ID %s.",
    existingLineItemId, response.getDuplicateLineItemId());

Python

# Provide the ID of the parent advertiser.
advertiser_id = advertiser-id

# Provide the ID of the existing line item to duplicate.
existing_line_item_id = existing-line-item-id

# Provide the display name of the line item to generate.
display_name = display-name

# Provide whether the line item will serve EU political ads.
contains_eu_political_ads = contains-eu-political-ads

# Create a line item duplication request.
duplication_request = {
    "targetDisplayName": display_name,
    "containsEuPoliticalAds": contains_eu_political_ads,
}

# Build and execute request.
duplication_response = (
    service.advertisers()
    .lineItems()
    .duplicate(
        advertiserId=advertiser_id,
        lineItemId=existing_line_item_id,
        body=duplication_request,
    )
    .execute()
)

# Print the ID of the new line item.
print(
    f"Line item ID {existing_line_item_id} was duplicated to create line"
    " item ID "
    f'{duplication_response["duplicateLineItemId"]}.'
)

PHP

// Provide the ID of the parent advertiser.
$advertiserId = advertiser-id;

// Provide the ID of the existing line item to duplicate.
$existingLineItemId = existing-line-item-id;

// Provide the display name of the line item to generate.
$displayName = display-name;

// Provide whether the line item will serve EU political ads.
$containsEuPoliticalAds = contains-eu-political-ads;

// Create the duplicate line item request structure.
$request = new Google_Service_DisplayVideo_DuplicateLineItemRequest();
$request->setTargetDisplayName($displayName);
$request->setContainsEuPoliticalAds($containsEuPoliticalAds);

// Call the API, duplicating the line item with the given display name.
try {
    $result = $this->service->advertisers_lineItems->create(
        $advertiserId,
        $existingLineItemId,
        $request
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the new line item ID.
printf(
    '<p>Line Item ID %s was duplicated to create line item ID %s</p>',
    $existingLineItemId,
    $result['duplicateLineItemId']
);