Tất cả 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ỉ định và Mục hàng đều được dùng cùng lúc để đặ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 có sẵn, chỉ định tuỳ chọn nhắm mục tiêu cho các mục hàng và thực hiện thao tác hàng loạt đối với các mục hàng để liệt kê và chỉnh sửa các tuỳ chọn nhắm mục tiêu được chỉ định.
Tìm các lựa chọn nhắm mục tiêu có sẵn
Tuỳ chọn nhắm mục tiêu sử dụng các biến do người dùng chỉ định, 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 sẵn có đượ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ã nhận dạng thực thể thông qua API Display & Video 360.
Sử dụng đặt giá trị enum
Tuỳ chọn nhắm mục tiêu cho các loại nhắm mục tiêu sau đây được chỉ định bằng các loại enum cụ thể:
TargetingType |
Liệt kê |
---|---|
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 liên quan để xác định tài nguyên AssignedTargetingOption
hiện có của các loại 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ị đại diện 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 ID tùy chọn nhắm mục tiêu
Những loại nhắm mục tiêu sử dụng các tuỳ chọn có sẵn được chỉ định bằ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 loại tiêu chí nhắm mục tiêu TARGETING_TYPE_ON_SCREEN_POSITION
. Mỗi vị trí này có một mã tuỳ 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, việc truy xuất được thực hiện theo một trong 2 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 phương thức
get
vàlist
. Sử dụngtargetingTypes.targetingOptions.get
để truy xuất thông tin chi tiết về tuỳ chọn nhắm mục tiêu được xác định theo loại nhắm mục tiêu và mã tuỳ chọn nhắm mục tiêu. Sử dụngtargetingTypes.targetingOptions.list
để liệt kê tất cả các tuỳ 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_POI
vàTARGETING_TYPE_BUSINESS_CHAIN
) bằng phương thứcsearch
. Sử dụngtargetingTypes.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 chuỗi truy vấn nhất định.
Dưới đâ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ể có 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']
1.199
// 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ã của thực thể đó. 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ợp và nhóm nguồn khoảng không quảng cáo, có thể truy xuất được thông qua dịch vụ riêng của chúng trong API Display & Video 360.
Mỗi dịch vụ đều có các phương thức get
và list
riêng. Sử dụng phương thức get
để xác nhận rằng một thực thể có sẵn cho một nhà quảng cáo nhất định. Hãy sử dụng phương thức list
để khám phá tất cả các thực thể của loại tài nguyên đó được cung cấp cho một nhà quảng cáo nhất định, nhờ đó có thể sử 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. Bạn có thể thực hiện việc này thông qua các phương thức create
và patch
trong dịch vụ tương ứng, cũng như các dịch vụ cho các giá trị riêng lẻ đượ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ủ định và vị 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 theo địa điểm quan tâm đã đặ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ã tuỳ chọn nhắm mục tiêu TARGETING_TYPE_POI
riêng để nhắm mục tiêu các toạ độ kinh độ – vĩ độ cụ thể.
Làm theo các bước sau để tạo ID tùy chọn nhắm mục tiêu POI:
- Truy xuất toạ độ kinh độ – vĩ độ (ví dụ: "40.7414691, -74.003387")
- Làm tròn giá trị toạ độ đến chữ số thập phân thứ sáu (ví dụ: "40.741469, -74.003387")
- Xoá chữ số thập phân khỏi giá trị toạ độ (ví dụ: "40741469, -74003387")
- Hãy nối hai giá trị này để tạo thành một chuỗi duy nhất, phân tách bằng dấu chấm phẩy (ví dụ: "40741469;-74003387")
Chuỗi kết quả có thể được sử dụng làm targetingOptionId
khi tạo tuỳ chọn nhắm mục tiêu được chỉ định TARGETING_TYPE_POI
.
Khi tạo, các trường targetingOptionId
và assignedTargetingOptionId
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 gồm chữ và số.
Chỉ định tuỳ chọn nhắm mục tiêu
Tiêu chí nhắm mục tiêu chỉ định cho 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. Khi bạn tạo một tuỳ chọn nhắm mục tiêu được chỉ định, các thông tin nhắm mục tiêu đó sẽ được áp dụng cho mục hàng mẹ. Việc xoá 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 tham 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 tiêu chí nhắm mục tiêu dự kiến.
Dưới đây là ví dụ về cách tạo tuỳ chọn nhắm mục tiêu được chỉ định của 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"])
1.199
// 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 việc nhắm mục tiêu trong Display & Video 360. Các chính sách 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 mà API trả về sẽ chỉ rõ lỗi vi phạm.
Lỗi chủ yếu là do tiêu chí nhắm mục tiêu hiện có được chỉ định cho một mục hàng. Hãy sử dụng advertisers.lineItems.targetingTypes.assignedTargetingOptions.list
để truy xuất tất cả các tuỳ chọn nhắm mục tiêu của một loại 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 trong trường hợp có giới hạn hay không và 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 cố gắng tạo lại tuỳ chọn nhắm mục tiêu được chỉ định mong muốn.
Lỗi nhắm mục tiêu của 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 các chiến dịch YouTube và Đối tác bằng API Display & Video 360, nếu không thì sẽ dẫn đến 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ư bất kỳ tiêu chí nhắm mục tiêu nào thuộc các loại nhắm mục tiêu sau đây:
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 các 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 tuỳ chọn nhắm mục tiêu được chỉ định cho một
mục hàng cùng 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 thực hiện liên tiếp yêu cầu advertisers.lineItems.patch
và yêu cầu nhắm mục tiêu có liên quan để đả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 các phương pháp nhắm mục tiêu hàng loạt và trê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 tuỳ chọn nhắm mục tiêu trên nhiều loại 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 thực hiện các cập nhật tương tự đối với tiêu chí nhắm mục tiêu trên nhiều mục hàng bằng cách sử dụngadvertisers.lineItems.bulkEditAssignedTargetingOptions
. Các chỉ số 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 nhắm mục tiêu trong một tài nguyên. Các định dạng này có trong các dịch vụ
partners
,advertisers
,advertisers.campaigns
vàadvertisers.insertionOrders
và được đặt tên làlistAssignedTargetingOptions
hoặceditAssignedTargetingOptions
.
Nếu bạn muốn có thông tin đầy đủ về tiêu chí nhắm mục tiêu hiện tại của mục hàng, muốn áp dụng cấu hình nhắm mục tiêu đặt trước cho 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ục hàng cùng một lúc, hãy cân nhắc sử dụng các phương pháp nhắm mục tiêu này.
Nhắm mục tiêu hàng loạt
advertisers.lineItems.bulkListAssignedTargetingOptions
cung cấp một cách xem xét tất cả cá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 các loại tiêu chí nhắm mục tiêu khác nhau. 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ể 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 tuỳ chọn nhắm mục tiêu được chỉ định cho một mục hàng được đố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']
1.199
// 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 hàng loạt tiêu chí nhắm mục tiêu
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 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ể biểu thị việc xoá hoặc tạo nhiều tuỳ chọn nhắm mục tiêu được chỉ định cùng loại nhắm mục tiêu.
Nếu việc cố gắng xoá hoặc tạo một tuỳ chọn nhắm mục tiêu được chỉ định gây ra lỗi cho mục hàng, thì thao tác hàng loạt sẽ bị bỏ qua đối với mục hàng đó. Yêu cầu này 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 mục hàng không cập nhật được và cá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 tuỳ chọn nhắm mục tiêu được chỉ định cho một hoặc nhiều mục hàng với danh sách các tuỳ chọn nhắm mục tiêu được chỉ định cần xoá và tiêu chí 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"]))
1.199
// 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'); }