บริการตัวเลือกการกำหนดเป้าหมาย ตัวเลือกการกำหนดเป้าหมายที่กำหนด และรายการโฆษณาทั้งหมดต่างใช้ร่วมกันเพื่อตั้งค่าการกำหนดเป้าหมายรายการโฆษณาใน API ของ Display & Video 360 หน้านี้จะอธิบายและแสดงตัวอย่างวิธีค้นหาตัวเลือกการกำหนดเป้าหมายที่ใช้ได้ กำหนดตัวเลือกการกำหนดเป้าหมายให้กับรายการโฆษณา และดำเนินการแบบกลุ่มกับรายการโฆษณาเพื่อแสดงและแก้ไขตัวเลือกการกำหนดเป้าหมายที่กำหนดไว้
ดูตัวเลือกการกำหนดเป้าหมายที่ใช้ได้
ตัวเลือกการกำหนดเป้าหมายจะใช้ตัวแปรที่ระบุโดยผู้ใช้ เอนทิตีที่กำหนดเป้าหมายได้ที่มีอยู่ หรือตัวเลือกที่มีอยู่ก่อนแล้วเพื่อกำหนดผู้ชมเป้าหมายที่ต้องการ ตัวเลือกที่มีอยู่แล้วจะระบุโดยใช้ค่า enum หรือรหัสตัวเลือกการกำหนดเป้าหมาย โดยขึ้นอยู่กับประเภทการกำหนดเป้าหมาย ระบบจะระบุเอนทิตีที่กำหนดเป้าหมายได้ โดยใช้รหัสเอนทิตี คุณดูรหัสตัวเลือกการกำหนดเป้าหมายและรหัสเอนทิตีได้โดยใช้ Display & Video 360 API
ใช้ค่า enum ที่ตั้งไว้
ระบบจะกำหนดตัวเลือกการกำหนดเป้าหมายสำหรับประเภทการกำหนดเป้าหมายต่อไปนี้โดยใช้ประเภท enum ที่เจาะจง
TargetingType |
ค่าแจกแจง |
---|---|
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 |
สามารถใช้เวอร์ชันสตริงของค่า enum ที่เกี่ยวข้องเพื่อระบุทรัพยากร AssignedTargetingOption
ที่มีอยู่ของประเภทการกำหนดเป้าหมายเหล่านี้ และมีอยู่ในช่อง assignedTargetingOptionIdAlias
คุณจะใช้ค่าชื่อแทนนี้แทน assignedTargetingOptionId
ได้เมื่อดึงข้อมูลหรือลบตัวเลือกการกำหนดเป้าหมายที่กำหนด
เรียกดูรหัสตัวเลือกการกำหนดเป้าหมาย
ประเภทการกำหนดเป้าหมายที่ใช้ตัวเลือกที่มีอยู่แล้วจะกำหนดโดยใช้รหัสตัวเลือกการกำหนดเป้าหมายที่เกี่ยวข้อง
เช่น มีตำแหน่งบนหน้าจอจำนวนจำกัดซึ่งกำหนดเป้าหมายได้โดยใช้ประเภทการกำหนดเป้าหมาย TARGETING_TYPE_ON_SCREEN_POSITION
โดยแต่ละตำแหน่งจะมีรหัสตัวเลือกการกำหนดเป้าหมายที่เกี่ยวข้อง
คุณเรียกดูรหัสตัวเลือกการกำหนดเป้าหมายเหล่านี้ได้ผ่านทางบริการตัวเลือกการกำหนดเป้าหมาย การดึงข้อมูลจะทำงานด้วยวิธีใดวิธีหนึ่งใน 2 วิธีต่อไปนี้ ทั้งนี้ขึ้นอยู่กับประเภทการกำหนดเป้าหมาย
- รายการดึงข้อมูลแต่ละรายการหรือรายการโดยสังเขป: ดึงข้อมูลตัวเลือกสำหรับประเภทการกำหนดเป้าหมายส่วนใหญ่ได้โดยใช้เมธอด
get
และlist
ใช้targetingTypes.targetingOptions.get
เพื่อเรียกรายละเอียดของตัวเลือกการกำหนดเป้าหมายที่ระบุโดยประเภทการกำหนดเป้าหมายและรหัสตัวเลือกการกำหนดเป้าหมาย ใช้targetingTypes.targetingOptions.list
เพื่อแสดงรายการตัวเลือกการกำหนดเป้าหมายทั้งหมดที่มีของประเภทการกำหนดเป้าหมายหนึ่งๆ - การค้นหา: ต้องเรียกข้อมูลตัวเลือกสำหรับประเภทการกำหนดเป้าหมายตามสถานที่
(
TARGETING_TYPE_GEO_REGION
,TARGETING_TYPE_POI
และTARGETING_TYPE_BUSINESS_CHAIN
) โดยใช้เมธอดsearch
ใช้targetingTypes.targetingOptions.search
เพื่อเรียกตัวเลือกการกำหนดเป้าหมายของประเภทหนึ่งๆ ที่ตรงกับสตริงคำค้นหาที่ระบุ
ตัวอย่างวิธีเรียกข้อมูลรายการตัวเลือกการกำหนดเป้าหมายที่เป็นไปได้สำหรับประเภทการกำหนดเป้าหมาย 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 );
แสดงรายการเอนทิตีที่กำหนดเป้าหมายได้
คุณต้องมีรหัสของเอนทิตีนั้นจึงจะกำหนดเป้าหมายรายการโฆษณาโดยใช้เอนทิตีที่กำหนดเป้าหมายได้ที่มีอยู่ เอนทิตีที่กำหนดเป้าหมายได้ เช่น แชแนล กลุ่มเป้าหมายแบบรวม และกลุ่มแหล่งที่มาของพื้นที่โฆษณาจะดึงข้อมูลได้ผ่านบริการของตนใน Display & Video 360 API
แต่ละบริการมีเมธอด get
และ list
ของตนเอง ใช้เมธอด get
เพื่อยืนยันว่าเอนทิตีพร้อมใช้งานภายใต้ผู้ลงโฆษณานั้นๆ ใช้เมธอด list
เพื่อค้นหาเอนทิตีทั้งหมดของประเภททรัพยากรดังกล่าวที่พร้อมให้บริการแก่ผู้ลงโฆษณาที่ระบุ และเพื่อจะใช้กำหนดการกำหนดเป้าหมายให้กับรายการโฆษณาภายใต้ผู้ลงโฆษณาดังกล่าวได้
ชุดย่อยของเอนทิตีที่กำหนดเป้าหมายได้ยังสามารถจัดการผ่าน API ได้เช่นกัน ซึ่งทำได้ผ่านเมธอด create
และ patch
ในบริการที่เกี่ยวข้อง รวมถึงบริการสำหรับค่าแต่ละค่าที่แสดงในเอนทิตี เช่น แหล่งที่มาของพื้นที่โฆษณา คีย์เวิร์ดเชิงลบ และสถานที่ตั้ง
รหัสตัวเลือกการกำหนดเป้าหมายจุดที่น่าสนใจของการสร้าง
คุณสามารถดึงข้อมูลตัวเลือกการกำหนดเป้าหมายจุดสนใจที่มีชื่อในส่วน TARGETING_TYPE_POI
ได้โดยใช้ targetingTypes.targetingOptions.search
นอกจากนี้ คุณยังสร้างรหัสตัวเลือกการกำหนดเป้าหมาย TARGETING_TYPE_POI
เฉพาะเพื่อกำหนดเป้าหมายพิกัดละติจูด-ลองจิจูดเฉพาะได้ด้วย
ทำตามขั้นตอนต่อไปนี้เพื่อสร้างรหัสตัวเลือกการกำหนดเป้าหมายจุดที่น่าสนใจ
- ดึงข้อมูลพิกัดละติจูด-ลองจิจูด (เช่น "40.7414691, -74.003387")
- ปัดเศษค่าพิกัดเป็นทศนิยมหลักที่ 6 (เช่น "40.741469, -74.003387")
- นำตำแหน่งทศนิยมออกจากค่าพิกัด (เช่น "40741469, -74003387")
- เชื่อมค่า 2 ค่าเข้าด้วยกันเพื่อให้เป็นสตริงเดียว โดยคั่นด้วยเครื่องหมายเซมิโคลอน (เช่น "40741469;-74003387")
สตริงผลลัพธ์จะใช้เป็น targetingOptionId
ได้เมื่อสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนด TARGETING_TYPE_POI
เมื่อสร้างแล้ว ระบบจะอัปเดตช่อง targetingOptionId
และ assignedTargetingOptionId
ของทรัพยากรตัวเลือกการกำหนดเป้าหมายที่กำหนด โดยเติมเครื่องหมายเซมิโคลอนและแฮชที่เป็นตัวอักษรและตัวเลขคละกัน
กำหนดตัวเลือกการกำหนดเป้าหมาย
การกำหนดเป้าหมายที่กำหนดให้กับรายการโฆษณาจะแสดงเป็นตัวเลือกการกำหนดเป้าหมายที่มอบหมาย คุณจะจัดการเอนทิตีเหล่านี้ได้โดยใช้บริการตัวเลือกการกำหนดเป้าหมายที่มอบหมาย การสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนดจะนำรายละเอียดการกำหนดเป้าหมายเหล่านั้นไปใช้กับรายการโฆษณาหลัก การลบตัวเลือกการกำหนดเป้าหมายที่กำหนดที่มีอยู่จะนำการกำหนดเป้าหมายนั้นออก
ใช้ advertisers.lineItems.targetingTypes.assignedTargetingOptions.create
เพื่อสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนด ระบุพารามิเตอร์การกำหนดเป้าหมายในช่อง details
ของทรัพยากรตัวเลือกการกำหนดเป้าหมายที่กำหนดซึ่งตรงกับประเภทการกำหนดเป้าหมายที่ต้องการ
ด้านล่างนี้เป็นตัวอย่างวิธีสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนดของประเภทการกำหนดเป้าหมาย 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'] );
ข้อผิดพลาด
ข้อผิดพลาดในการกำหนดค่าการกำหนดเป้าหมาย
มีกฎที่ซับซ้อนมากมายเกี่ยวกับการกำหนดเป้าหมายใน Display & Video 360 ซึ่งจะบังคับใช้ใน API ของ Display & Video 360 ผ่านข้อผิดพลาดที่ส่งกลับเมื่อสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนด ข้อผิดพลาดที่แสดงโดย API จะระบุการละเมิด
ข้อผิดพลาดส่วนใหญ่เกิดจากการกำหนดเป้าหมายที่มีอยู่เดิมซึ่งกำหนดให้กับรายการโฆษณา ใช้ advertisers.lineItems.targetingTypes.assignedTargetingOptions.list
เพื่อดึงตัวเลือกการกำหนดเป้าหมายทั้งหมดของประเภทการกำหนดเป้าหมายหนึ่งๆ ที่กำหนดให้กับรายการโฆษณา ประเมินว่าการกำหนดเป้าหมายที่ต้องการจะเป็นไปได้หรือไม่จากข้อจำกัด และใช้ advertisers.lineItems.targetingTypes.assignedTargetingOptions.delete
เพื่อนำการกำหนดเป้าหมายที่ไม่ต้องการออก ก่อนที่จะพยายามสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนดที่ต้องการอีกครั้ง
ข้อผิดพลาดในการกำหนดเป้าหมายสำหรับ YouTube และพาร์ทเนอร์
อัปเดตการกำหนดเป้าหมายสำหรับแคมเปญ YouTube และพาร์ทเนอร์โดยเฉพาะโดยใช้ Display & Video 360 API ไม่ได้ และการพยายามทำเช่นนั้นจะทำให้เกิดข้อผิดพลาด
การกำหนดเป้าหมาย YouTube และพาร์ทเนอร์ประกอบด้วยการกำหนดเป้าหมายทั้งหมดที่กำหนดให้กับรายการโฆษณาและกลุ่มโฆษณา YouTube และพาร์ทเนอร์โดยตรง รวมถึงการกำหนดเป้าหมายตามประเภทการกำหนดเป้าหมายต่อไปนี้
TARGETING_TYPE_SESSION_POSITION
TARGETING_TYPE_YOUTUBE_CHANNEL
TARGETING_TYPE_YOUTUBE_VIDEO
ข้อผิดพลาดในการเกิดขึ้นพร้อมกัน
การพยายามอัปเดตการตั้งค่าหรือการกำหนดเป้าหมายของรายการโฆษณาเดียวผ่านคำขอหลายรายการพร้อมกันจะทำให้เกิดข้อผิดพลาด
หากคุณต้องการเพิ่มหรือนำตัวเลือกการกำหนดเป้าหมายที่กำหนดไว้หลายรายการสำหรับรายการโฆษณาเดียวออกพร้อมกัน คุณควรใช้คำขอแก้ไขจำนวนมาก หากต้องการอัปเดตการตั้งค่าและการกำหนดเป้าหมายของรายการโฆษณา ให้สร้างคำขอ advertisers.lineItems.patch
และคำขอการกำหนดเป้าหมายที่เกี่ยวข้องตามลำดับ เพื่อไม่ให้มีการส่งคำขอที่ 2 จนกว่าคำขอแรกจะส่งกลับ
การดำเนินการกำหนดเป้าหมายจำนวนมากและทั่วทั้งทรัพยากร
คุณสามารถใช้วิธีการกำหนดเป้าหมายจำนวนมากและทั่วทั้งทรัพยากรเพื่อจัดการตัวเลือกการกำหนดเป้าหมายที่กำหนดในประเภทการกำหนดเป้าหมายต่างๆ ต่อไปนี้
- ใช้วิธีการกำหนดเป้าหมายจำนวนมากเพื่อเรียกคืนหรือแก้ไขตัวเลือกการกำหนดเป้าหมายในการกำหนดเป้าหมายหลายประเภทและภายใต้ทรัพยากรจำนวนมาก คุณดึงข้อมูลการกำหนดค่าการกำหนดเป้าหมายแบบเต็มของรายการโฆษณาหลายรายการได้โดยใช้
advertisers.lineItems.bulkListAssignedTargetingOptions
หรือทำการอัปเดตการกำหนดเป้าหมายเดียวกันในหลายๆ รายการโฆษณาโดยใช้advertisers.lineItems.bulkEditAssignedTargetingOptions
ฟีเจอร์เหล่านี้ใช้ได้เฉพาะในบริการadvertisers.lineItems
เท่านั้น - ใช้วิธีการกำหนดเป้าหมายทั่วทั้งทรัพยากรเพื่อเรียกหรือแก้ไขตัวเลือกการกำหนดเป้าหมายในการกำหนดเป้าหมายหลายประเภทภายใต้ทรัพยากรเดียว ซึ่งพร้อมให้ใช้งานในบริการ
partners
,advertisers
,advertisers.campaigns
และadvertisers.insertionOrders
และใช้ชื่อว่าlistAssignedTargetingOptions
หรือeditAssignedTargetingOptions
หากคุณต้องการมุมมองที่สมบูรณ์ของการกำหนดเป้าหมายปัจจุบันของรายการโฆษณา ต้องการใช้การกำหนดค่าการกำหนดเป้าหมายที่กำหนดไว้ล่วงหน้ากับรายการโฆษณา หรือต้องการเปลี่ยนแปลงการกำหนดเป้าหมายของรายการโฆษณาหลายรายการพร้อมกัน ให้ลองใช้วิธีการกำหนดเป้าหมายเหล่านี้
การกำหนดเป้าหมายรายการจำนวนมาก
advertisers.lineItems.bulkListAssignedTargetingOptions
มีวิธีดูการกำหนดเป้าหมายทั้งหมดที่กำหนดให้กับรายการโฆษณาอย่างน้อย 1 รายการในการกำหนดเป้าหมายประเภทต่างๆ โดยจะทำงานคล้ายกับวิธี list
อื่นๆ คุณสามารถใช้พารามิเตอร์การค้นหา filter
เพื่อกรองผลลัพธ์ตาม TargetingType
หรือ Inheritance
ด้านล่างนี้เป็นตัวอย่างวิธีแสดงตัวเลือกการกำหนดเป้าหมายทั้งหมดที่กำหนดให้กับรายการโฆษณาซึ่งมาจากพาร์ทเนอร์หรือผู้ลงโฆษณาหลัก
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);
แก้ไขการกำหนดเป้าหมายจำนวนมาก
advertisers.lineItems.bulkEditAssignedTargetingOptions
เป็นวิธีเพิ่มและนำตัวเลือกการกำหนดเป้าหมายหลายประเภทของประเภทการกำหนดเป้าหมายต่างๆ ออกจากรายการโฆษณาอย่างน้อย 1 รายการพร้อมกัน
เมธอดจะใช้รายการ DeleteAssignedTargetingOptionsRequests
และลิสต์ของ CreateAssignedTargetingOptionsRequests
ออบเจ็กต์คำขอเดียวแสดงถึงการลบหรือสร้างตัวเลือกการกำหนดเป้าหมายหลายรายการที่มีประเภทการกำหนดเป้าหมายเดียวกัน
หากการพยายามลบหรือสร้างตัวเลือกการกำหนดเป้าหมายที่กำหนดทำให้เกิดข้อผิดพลาดสำหรับรายการโฆษณา การดำเนินการแบบกลุ่มสำหรับรายการโฆษณานั้นจะยกเลิก คำขอจะแสดงรายการโฆษณาที่อัปเดตสำเร็จ รวมถึงรายการรายการโฆษณาที่ไม่อัปเดตและข้อผิดพลาดที่เกี่ยวข้อง
ต่อไปนี้คือตัวอย่างวิธีแก้ไขตัวเลือกการกำหนดเป้าหมายที่กำหนดแบบเป็นกลุ่มสำหรับรายการโฆษณาอย่างน้อย 1 รายการ โดยใช้รายการตัวเลือกการกำหนดเป้าหมายที่กำหนดเพื่อลบและตัวเลือกการกำหนดเป้าหมายที่จะสร้าง
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'); }