Hướng dẫn này mô tả các phương pháp mà bạn có thể sử dụng để xem phân khúc dữ liệu.
Trước khi bắt đầu
Trước khi tiếp tục, bạn phải thiết lập quy trình xác thực.
Xem một phân khúc dữ liệu riêng lẻ
Để xem một trong các phân khúc dựa trên dữ liệu của bạn, hãy sử dụng phương thức curators.dataSegments.get.
Ví dụ sau đây đưa ra yêu cầu GET đối với phương thức curators.dataSegments.get, phương thức này sẽ phản hồi bằng phân khúc dữ liệu được chỉ định.
REST
Yêu cầu
curl \
'https://curationpartners.googleapis.com/v1/curators/ACCOUNT_ID/dataSegments/test-data-segment-1' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Accept: application/json' \
--compressed
Thay thế nội dung sau:
ACCOUNT_ID: mã tài khoản của bạnACCESS_TOKEN: mã truy cập của bạn.
Phản hồi
{
"name": "curators/ACCOUNT_ID/dataSegments/test-data-segment-1",
"createTime": "2025-08-13T12:14:03.421Z",
"updateTime": "2025-08-14T19:47:40.253938Z",
"cpmFee": {
"currencyCode": "USD",
"units": "1000000"
},
"state": "INACTIVE"
}
Java
/* * Copyright (c) 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.api.services.samples.authorizedbuyers.marketplace.v1beta.curators.dataSegments; import com.google.api.services.authorizedbuyersmarketplace.v1beta.AuthorizedBuyersMarketplace; import com.google.api.services.authorizedbuyersmarketplace.v1beta.model.DataSegment; import com.google.api.services.authorizedbuyersmarketplace.v1beta.model.ListDataSegmentsResponse; import com.google.api.services.authorizedbuyersmarketplace.v1beta.model.Money; import com.google.api.services.samples.authorizedbuyers.marketplace.v1beta.Utils; import java.io.IOException; import java.security.GeneralSecurityException; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; public class GetDataSegment { private GetDataSegment() {} /** * Executes the get operation for a data segment. * * @param marketplaceClient the initialized Marketplace API client. * @param accountId the account ID of the curator that created the data segment. * @param dataSegmentId the resource ID of the data segment to retrieve. * @throws IOException if the API returns an error. */ public static void execute( AuthorizedBuyersMarketplace marketplaceClient, Long accountId, String dataSegmentId) throws IOException { String name = String.format("curators/%d/dataSegments/%s", accountId, dataSegmentId); System.out.printf("Get data segment with name \"%s\".%n", name); DataSegment response = marketplaceClient.curators().dataSegments().get(name).execute(); System.out.println("Successfully retrieved data segment:"); Utils.jsonPrettyPrint(response); } /** * Creates and configures the ArgumentParser for this sample. * * @return the configured ArgumentParser. */ private static ArgumentParser createArgumentParser() { ArgumentParser parser = ArgumentParsers.newFor("GetDataSegment") .build() .defaultHelp(true) .description("Gets a specified data segment for the given curator account."); // Required arguments. parser .addArgument("-a", "--account_id") .help("The account ID of the curator that created the data segment.") .required(true) .type(Long.class); parser .addArgument("-d", "--data_segment_id") .help("The resource ID of the data segment to retrieve.") .required(true); return parser; } public static void main(String[] args) { ArgumentParser parser = createArgumentParser(); Namespace parsedArgs = null; try { parsedArgs = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } AuthorizedBuyersMarketplace client = null; try { client = Utils.getMarketplaceClient(); } catch (IOException ex) { System.out.printf("Unable to create Marketplace API service:%n%s", ex); System.out.println("Did you specify a valid path to a service account key file?"); System.exit(1); } catch (GeneralSecurityException ex) { System.out.printf("Unable to establish secure HttpTransport:%n%s", ex); System.exit(1); } Long accountId = parsedArgs.getLong("account_id"); String dataSegmentId = parsedArgs.getString("data_segment_id"); try { execute(client, accountId, dataSegmentId); } catch (Exception e) { System.out.printf("Marketplace API returned error response:%n%s", e); System.exit(1); } } }
Xem danh sách tất cả các phân khúc dữ liệu của bạn
Để xem tất cả các phân khúc dựa trên dữ liệu, hãy sử dụng phương thức curators.dataSegments.list.
Ví dụ sau đây đưa ra yêu cầu GET đối với phương thức curators.dataSegments.list. Phương thức này sẽ phản hồi bằng tất cả phân đoạn dữ liệu cho tài khoản người tuyển chọn được chỉ định.
REST
Yêu cầu
curl \
'https://curationpartners.googleapis.com/v1/curators/ACCOUNT_ID/dataSegments' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Accept: application/json' \
--compressed
Phản hồi
{
"dataSegments": [
{
"name": "curators/ACCOUNT_ID/dataSegments/test-data-segment-1",
"createTime": "2025-08-13T12:14:03.421Z",
"updateTime": "2025-08-14T20:05:51.439110Z",
"cpmFee": {
"currencyCode": "USD",
"units": "1"
},
"state": "INACTIVE"
},
{
"name": "curators/ACCOUNT_ID/dataSegments/test-data-segment-2",
"createTime": "2025-08-14T17:45:08.744Z",
"updateTime": "2025-08-14T17:56:02.200619Z",
"cpmFee": {
"currencyCode": "USD",
"nanos": 50
},
"state": "ACTIVE"
}
]
}
Java
/* * Copyright (c) 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.api.services.samples.authorizedbuyers.marketplace.v1beta.curators.dataSegments; import com.google.api.services.authorizedbuyersmarketplace.v1beta.AuthorizedBuyersMarketplace; import com.google.api.services.authorizedbuyersmarketplace.v1beta.model.DataSegment; import com.google.api.services.authorizedbuyersmarketplace.v1beta.model.ListDataSegmentsResponse; import com.google.api.services.authorizedbuyersmarketplace.v1beta.model.Money; import com.google.api.services.samples.authorizedbuyers.marketplace.v1beta.Utils; import java.io.IOException; import java.security.GeneralSecurityException; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; public class ListDataSegments { private ListDataSegments() {} /** * Executes the list operation for a curator account's data segments. * * @param marketplaceClient the initialized Marketplace API client. * @param parent the parent resource name under which the data segments will be listed. * @param pageSize the number of rows to return per page. * @throws IOException if the API returns an error. */ public static void execute( AuthorizedBuyersMarketplace marketplaceClient, String parent, Integer pageSize) throws IOException { String pageToken = null; // Iterate through and print pages from the dataSegments.list response. do { ListDataSegmentsResponse response = marketplaceClient .curators() .dataSegments() .list(parent) .setPageSize(pageSize) .setPageToken(pageToken) .execute(); Utils.jsonPrettyPrint(response); pageToken = response.getNextPageToken(); } while (pageToken != null); } /** * Creates and configures the ArgumentParser for this sample. * * @return the configured ArgumentParser. */ private static ArgumentParser createArgumentParser() { ArgumentParser parser = ArgumentParsers.newFor("ListDataSegments") .build() .defaultHelp(true) .description("Lists data segments for the given curator account."); // Required arguments. parser .addArgument("-a", "--account_id") .help("The account ID of the curator whose data segments will be listed.") .required(true) .type(Long.class); // Optional arguments. parser .addArgument("-d", "--page_size") .help( "The number of rows to return per page. The server may return fewer rows than " + "specified.") .type(Integer.class); return parser; } public static void main(String[] args) { ArgumentParser parser = createArgumentParser(); Namespace parsedArgs = null; try { parsedArgs = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } AuthorizedBuyersMarketplace client = null; try { client = Utils.getMarketplaceClient(); } catch (IOException ex) { System.out.printf("Unable to create Marketplace API service:%n%s", ex); System.out.println("Did you specify a valid path to a service account key file?"); System.exit(1); } catch (GeneralSecurityException ex) { System.out.printf("Unable to establish secure HttpTransport:%n%s", ex); System.exit(1); } String parent = String.format("curators/%d", parsedArgs.getLong("account_id")); Integer pageSize = parsedArgs.getInt("page_size"); try { execute(client, parent, pageSize); } catch (Exception e) { System.out.printf("Marketplace API returned error response:%n%s", e); System.exit(1); } } }
Các bước tiếp theo
- Tìm hiểu cách kích hoạt và huỷ kích hoạt phân khúc dữ liệu bằng Curation Partners API.
- Tìm hiểu về quy cách Sắp xếp theo thời gian thực.
- Tìm hiểu cách phân tích cú pháp các yêu cầu phân đoạn đến trong tính năng Sắp xếp theo thời gian thực.