Kích hoạt tài nguyên

Sau khi tạo và định cấu hình các tài sản của chiến dịch Tạo nhu cầu, bạn có thể cập nhật các trường entityStatus của tài sản thành ENTITY_STATUS_ACTIVE để bắt đầu phân phát quảng cáo. Cả 3 tài nguyên này đều phải đang hoạt động để bắt đầu phân phát quảng cáo.

Bạn phải tạo tài nguyên LineItem bằng EntityStatus "bản nháp" và kích hoạt trong một yêu cầu tiếp theo. Bạn có thể tạo tài nguyên AdGroupAdGroupAd bằng EntityStatus "đang hoạt động", nhưng bạn nên tạo các tài nguyên này bằng trạng thái "đã tạm dừng". Bằng cách đó, bạn có thể chỉ định tiêu chí nhắm mục tiêu và xác minh cấu hình chính xác trước khi kích hoạt các tài nguyên trong các yêu cầu tiếp theo.

Kích hoạt mục hàng

Sau đây là cách kích hoạt một mục hàng:

Java

// The ID of the line item's parent advertiser.
long advertiserId = advertiser-id;

// The ID of the line item.
long lineItemId = line-item-id;

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

// Configure the patch request and set update mask to only update entity
// status.
LineItems.Patch request =
    service
        .advertisers()
        .lineItems()
        .patch(advertiserId, lineItemId, lineItem)
        .setUpdateMask("entityStatus");

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

// Display the new entity status of the updated line item.
System.out.printf(
    "LineItem %s now has entity status %s%n",
    response.getName(),
    response.getEntityStatus());

Python

# The ID of the line item's parent advertiser.
advertiser_id = advertiser-id

# The ID of the line item.
line_item_id = line-item-id

# Create the line item structure.
line_item_obj = {
    "entityStatus": "ENTITY_STATUS_ACTIVE",
}

# Build and execute request.
response = (
    service.advertisers()
    .lineItems()
    .patch(
        advertiserId=advertiser_id,
        lineItemId=line_item_id,
        updateMask="entityStatus",
        body=line_item_obj,
    )
    .execute()
)

# Display the entity status of the updated line item.
print(
    f"Line item {response['name']} now has entity status "
    f"{response['entityStatus']}."
)

PHP

// The ID of the line item's parent advertiser.
$advertiserId = advertiser-id;

// The ID of the line item.
$lineItemId = line-item-id;

// Create the line item structure.
$lineItem = new Google_Service_DisplayVideo_LineItem();
$lineItem->setEntityStatus('ENTITY_STATUS_ACTIVE');
$optParams = array('updateMask' => 'entityStatus');

// Call the API, updating the entity status for the identified line
// item.
try {
    $result = $this->service->advertisers_lineItems->patch(
        $advertiserId,
        $lineItemId,
        $lineItem,
        $optParams
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the entity status of the updated line item.
printf(
    '<p>Line Item %s now has entity status %s.</p>',
    $result['name'],
    $result['entityStatus']
);

Kích hoạt nhóm quảng cáo

Sau đây là cách kích hoạt một nhóm quảng cáo:

Java

// The ID of the ad group's parent advertiser.
long advertiserId = advertiser-id;

// The ID of the ad group.
long adGroupId = ad-group-id;

// Create the ad group structure.
AdGroup adGroup = new AdGroup().setEntityStatus("ENTITY_STATUS_ACTIVE");

// Configure the patch request and set update mask to only update entity
// status.
AdGroups.Patch request =
    service
        .advertisers()
        .adGroups()
        .patch(advertiserId, adGroupId, adGroup)
        .setUpdateMask("entityStatus");

// Update the ad group.
AdGroup response = request.execute();

// Display the entity status of the updated ad group.
System.out.printf(
    "Ad Group %s now has entity status %s%n",
    response.getName(),
    response.getEntityStatus());

Python

# The ID of the ad group's parent advertiser.
advertiser_id = advertiser-id

# The ID of the ad group.
ad_group_id = ad-group-id

# Create the ad group structure.
ad_group_obj = {
    "entityStatus": "ENTITY_STATUS_ACTIVE",
}

# Build and execute request.
response = (
    service.advertisers()
    .adGroups()
    .patch(
        advertiserId=advertiser_id,
        adGroupId=ad_group_id,
        updateMask="entityStatus",
        body=ad_group_obj,
    )
    .execute()
)

# Display the entity status of the updated ad group.
print(
    f"Ad group {response['name']} now has entity status "
    f"{response['entityStatus']}."
)

PHP

// The ID of the ad group's parent advertiser.
$advertiserId = advertiser-id;

// The ID of the ad group.
$adGroupId = ad-group-id;

// Create the ad group structure.
$adGroup = new Google_Service_DisplayVideo_AdGroup();
$adGroup->setEntityStatus('ENTITY_STATUS_ACTIVE');
$optParams = array('updateMask' => 'entityStatus');

// Call the API, updating the entity status for the identified ad group.
try {
    $result = $this->service->advertisers_adGroups->patch(
        $advertiserId,
        $adGroupId,
        $adGroup,
        $optParams
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the entity status of the updated ad group.
printf(
    '<p>Ad Group %s now has entity status %s.</p>',
    $result['name'],
    $result['entityStatus']
);

Kích hoạt quảng cáo

Sau đây là cách kích hoạt quảng cáo:

Java

// The ID of the ad's parent advertiser.
long advertiserId = advertiser-id;

// The ID of the ad.
long adId = ad-group-ad-id;

// Create the ad group ad structure.
AdGroupAd ad =
    new AdGroupAd().setEntityStatus("ENTITY_STATUS_ACTIVE");

// Configure the patch request and set update mask to only update entity
// status.
AdGroupAds.Patch request =
    service
        .advertisers()
        .adGroupAds()
        .patch(advertiserId, adId, ad)
        .setUpdateMask("entityStatus");

// Update the ad group.
AdGroupAd response = request.execute();

// Display the new entity status of the updated ad.
System.out.printf(
    "Ad %s now has entity status %s%n",
    response.getName(),
    response.getEntityStatus());

Python

# The ID of the ad's parent advertiser.
advertiser_id = advertiser-id

# The ID of the ad.
ad_id = ad-group-ad-id

# Create the ad group ad structure.
ad_obj = {
    "entityStatus": "ENTITY_STATUS_ACTIVE",
}

# Build and execute request.
response = (
    service.advertisers()
    .adGroupAds()
    .patch(
        advertiserId=advertiser_id,
        adGroupAdId=ad_id,
        updateMask="entityStatus",
        body=ad_obj,
    )
    .execute()
)

# Display the new entity status of the updated ad.
print(
    f"Ad {response['name']} now has entity status "
    f"{response['entityStatus']}."
)

PHP

// The ID of the ad's parent advertiser.
$advertiserId = advertiser-id;

// The ID of the ad.
$adId = ad-group-ad-id;

// Create the ad group ad structure.
$ad = new Google_Service_DisplayVideo_AdGroupAd();
$ad->setEntityStatus('ENTITY_STATUS_ACTIVE');
$optParams = array('updateMask' => 'entityStatus');

// Call the API, updating the entity status for the identified ad.
try {
    $result = $this->service->advertisers_adGroupAds->patch(
        $advertiserId,
        $adId,
        $ad,
        $optParams
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the new entity status of the updated ad.
printf(
    '<p>Ad %s now has entity status %s.</p>',
    $result['name'],
    $result['entityStatus']
);