Việc chạy báo cáo sẽ bắt đầu thực thi một mẫu Report hiện có để tạo dữ liệu hiệu suất cho tài khoản tuyển chọn của bạn.
Hướng dẫn này trình bày cách bạn có thể tạo báo cáo mô tả hiệu suất của tài khoản tuyển chọn bằng cách sử dụng Curation Partners API để chạy mẫu Report.
Trước khi bắt đầu
Trước khi tiếp tục, bạn phải hoàn tất các bước sau:
Bắt đầu chạy báo cáo
Để chạy một báo cáo hiện có, hãy sử dụng phương thức curators.reports.run.
Ví dụ sau đây đưa ra yêu cầu POST để bắt đầu chạy báo cáo:
REST
Yêu cầu
curl --request POST \
'https://curationpartners.googleapis.com/v1/curators/ACCOUNT_ID/reports/123456789:run' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{}' \
--compressed
Thay thế nội dung sau:
ACCOUNT_ID: mã tài khoản của bạn.ACCESS_TOKEN: mã truy cập của bạn.
Phản hồi
{
"name": "curators/ACCOUNT_ID/reports/123456789/operations/10486370264",
"done": false,
"metadata": {
"@type": "type.googleapis.com/google.ads.curationpartners.v1.RunReportMetadata"
}
}
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.curationpartners.v1.curators.reports; import com.google.api.services.curationpartners.v1.CurationPartners; import com.google.api.services.curationpartners.v1.model.Operation; import com.google.api.services.curationpartners.v1.model.RunReportRequest; import com.google.api.services.samples.curationpartners.v1.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 RunReport { /** * Executes the run operation for a report. * * @param curationPartnersClient the initialized Curation Partners API client. * @param accountId the account ID of the curator that created the report. * @param reportId the resource ID of the report to run. * @throws IOException if the API returns an error. */ public static void execute( CurationPartners curationPartnersClient, Long accountId, String reportId) throws IOException { String name = String.format("curators/%s/reports/%s", accountId, reportId); System.out.printf("Running report with name \"%s\".%n", name); RunReportRequest requestBody = new RunReportRequest(); // Run the specified report to start an asynchronous operation. Operation operation = curationPartnersClient .curators() .reports() .run(name, requestBody) .execute(); System.out.println("Successfully initiated report run operation:"); Utils.jsonPrettyPrint(operation); } /** * Creates and configures the ArgumentParser for this sample. * * @return the configured ArgumentParser. */ private static ArgumentParser createArgumentParser() { ArgumentParser parser = ArgumentParsers.newFor("RunReport") .build() .defaultHelp(true) .description("Runs a specified report asynchronously, returning an Operation " + "that can be used to track its progress."); // Required arguments. parser .addArgument("-a", "--account_id") .help("The account ID of the curator that created the report.") .required(true) .type(Long.class); parser .addArgument("-r", "--report_id") .help("The resource ID of the report to run.") .required(true); return parser; } public static void main(String[] args) { ArgumentParser parser = createArgumentParser(); Namespace parsedArgs = null; try { parsedArgs = parser.parseArgs(args); } catch (ArgumentParserException ex) { parser.handleError(ex); System.exit(1); } CurationPartners client = null; try { client = Utils.getCurationPartnersClient(); } catch (IOException ex) { System.out.printf("Unable to create Curation Partners 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); } try { execute( client, parsedArgs.getLong("account_id"), parsedArgs.getString("report_id")); } catch (IOException ex) { System.out.printf("Curation Partners API returned error response:%n%s", ex); System.exit(1); } } }
Chạy báo cáo là một thao tác không đồng bộ kéo dài. Khi bạn gọi phương thức run, Curation Partners API sẽ phản hồi bằng tài nguyên Operation. Trường name của thao tác xác định thao tác chạy và có định dạng sau:
curators/ACCOUNT_ID/reports/REPORT_ID/operations/OPERATION_ID
Đối tượng Operation được trả về chứa những nội dung sau:
name: tên do máy chủ chỉ định cho thao tác diễn ra trong thời gian dài.metadata: thông tin tiến trình dành riêng cho dịch vụ (không bắt buộc). Trườngmetadatacó thể không được điền sẵn trong đối tượngOperationmà bạn nhận được trong phản hồicurators.reports.run.
Sau khi bắt đầu chạy báo cáo, bạn không thể xem kết quả báo cáo cho đến khi trường done của thao tác có giá trị true. Thời gian cần thiết để hoàn tất một báo cáo chạy sẽ khác nhau tuỳ thuộc vào độ phức tạp của báo cáo.
Các bước tiếp theo
- Tìm hiểu cách bỏ phiếu và xem báo cáo đã hoàn tất bằng Curation Partners API.
- Tìm hiểu cách xem các báo cáo hiện có bằng Curation Partners API.