สำรวจและดูรายงานที่เสร็จสมบูรณ์แล้ว

การดำเนินการเรียกใช้รายงานจะทำงานแบบไม่พร้อมกันเป็นการดำเนินการที่ใช้เวลานาน ซึ่งแสดงด้วย Operation ออบเจ็กต์ เอาต์พุตของการดำเนินการเรียกใช้รายงานคือผลลัพธ์ของรายงานตามออบเจ็กต์ Report

คู่มือนี้อธิบายวิธีใช้ Curation Partners API เพื่อ ให้การดำเนินการเรียกใช้รายงานสำรวจสถานะของการดำเนินการ และดึงผลลัพธ์ของรายงานจากการดำเนินการ เรียกใช้รายงานที่เสร็จสมบูรณ์

ก่อนเริ่มต้น

ก่อนดำเนินการต่อ คุณต้องทำสิ่งต่อไปนี้ให้เสร็จสมบูรณ์

สำรวจสถานะการเรียกใช้รายงาน

หากต้องการตรวจสอบสถานะการดำเนินการของการดำเนินการเรียกใช้รายงาน ให้ใช้ curators.reports.operations.get เมธอด

ตัวอย่างต่อไปนี้จะส่งคำขอ GET เพื่อสำรวจการดำเนินการ

REST

ส่งคำขอ

curl \
  'https://curationpartners.googleapis.com/v1/curators/ACCOUNT_ID/reports/123456789/operations/10486370264' \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Accept: application/json' \
  --compressed

แทนที่ค่าต่อไปนี้

  • ACCOUNT_ID: รหัสบัญชีของคุณ
  • ACCESS_TOKEN: โทเค็นเพื่อการเข้าถึงของคุณ

คำตอบ

เมื่อเสร็จสมบูรณ์แล้ว การตอบกลับจะเป็น Operation ที่มีช่อง done ตั้งค่าเป็น true และเพย์โหลด response จะมีชื่อทรัพยากร reportResult

{
  "name": "curators/ACCOUNT_ID/reports/123456789/operations/10486370264",
  "done": true,
  "metadata": {
    "@type": "type.googleapis.com/google.ads.curationpartners.v1.RunReportMetadata",
    "percentComplete": 100
  },
  "response": {
    "@type": "type.googleapis.com/google.ads.curationpartners.v1.RunReportResponse",
    "reportResult": "curators/ACCOUNT_ID/reports/123456789/results/10486370264"
  }
}

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.operations;

import com.google.api.services.curationpartners.v1.CurationPartners;
import com.google.api.services.curationpartners.v1.model.Operation;
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 GetReportOperation {

  /**
   * Executes the get operation for a report operation.
   *
   * @param curationPartnersClient the initialized Curation Partners API client.
   * @param accountId the account ID of the curator.
   * @param reportId the resource ID of the report.
   * @param operationId the resource ID of the report operation.
   * @throws IOException if the API returns an error.
   */
  public static void execute(
      CurationPartners curationPartnersClient,
      Long accountId,
      String reportId,
      String operationId)
      throws IOException {
    String name =
        String.format(
            "curators/%s/reports/%s/operations/%s", accountId, reportId, operationId);

    System.out.printf("Getting report operation with name \"%s\".%n", name);

    // Get the status of the report operation.
    Operation operation =
        curationPartnersClient
            .curators()
            .reports()
            .operations()
            .get(name)
            .execute();

    System.out.println("Successfully retrieved report operation:");
    Utils.jsonPrettyPrint(operation);
  }

  /**
   * Creates and configures the ArgumentParser for this sample.
   *
   * @return the configured ArgumentParser.
   */
  private static ArgumentParser createArgumentParser() {
    ArgumentParser parser =
        ArgumentParsers.newFor("GetReportOperation")
            .build()
            .defaultHelp(true)
            .description("Gets the status of a long-running report operation. If the " +
                "operation is done, you can view the report contents with the " +
                "`curators.reports.results.fetchRows` method.");

    // Required arguments.
    parser
        .addArgument("-a", "--account_id")
        .help("The account ID of the curator.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-r", "--report_id")
        .help("The resource ID of the report.")
        .required(true);
    parser
        .addArgument("-o", "--operation_id")
        .help("The resource ID of the report operation 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 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"),
          parsedArgs.getString("operation_id"));
    } catch (IOException ex) {
      System.out.printf("Curation Partners API returned error response:%n%s", ex);
      System.exit(1);
    }
  }
}

ต่อไปนี้อธิบายวิธีใช้ช่อง done เพื่อสำรวจสถานะการดำเนินการ

  • หากช่อง done ในการตอบกลับมีค่า false แสดงว่าการดำเนินการเรียกใช้รายงานยังคงอยู่ระหว่างดำเนินการ
  • หากช่อง done ในการตอบกลับมีค่า true แสดงว่าการดำเนินการเรียกใช้รายงานเสร็จสมบูรณ์แล้ว ออบเจ็กต์ Operation ในเนื้อหาการตอบกลับจะมีช่องใดช่องหนึ่งต่อไปนี้ด้วย
    • response: บ่งชี้ว่าการดำเนินการเรียกใช้รายงานสำเร็จ ช่องนี้เป็นออบเจ็กต์ที่มีช่อง @type ตั้งค่าเป็นประเภท type.googleapis.com/google.ads.curationpartners.v1.RunReportResponse ประเภท RunReportResponse จะมีช่อง reportResult ที่มีชื่อของรายงานที่เกี่ยวข้อง result
    • error: บ่งชี้ว่าการดำเนินการเรียกใช้รายงานไม่สำเร็จ ช่อง error จะมีออบเจ็กต์ Status ที่อธิบายสาเหตุที่การเรียกใช้รายงานล้มเหลว

ดึงแถวจากรายงานที่เสร็จสมบูรณ์

คุณสามารถดึงเนื้อหาของการดำเนินการเรียกใช้รายงานที่เสร็จสมบูรณ์ด้วย curators.reports.results.fetchRows เมธอด คุณต้องกรอกพารามิเตอร์เส้นทาง name สำหรับผลลัพธ์ของรายงาน ซึ่งเป็นชื่อทรัพยากรจากช่อง reportResult ของการดำเนินการเรียกใช้รายงานที่เสร็จสมบูรณ์

ตัวอย่างต่อไปนี้จะส่งคำขอ GET เพื่อดึงแถวผลลัพธ์

REST

ส่งคำขอ

curl \
  'https://curationpartners.googleapis.com/v1/curators/ACCOUNT_ID/reports/123456789/results/10486370264:fetchRows?pageSize=1' \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Accept: application/json' \
  --compressed

คำตอบ

{
  "rows": [
    {
      "dimensionValues": [
        {
          "stringValue": "2026-08-01"
        },
        {
          "stringValue": "segment-1001"
        }
      ],
      "metricValueGroups": [
        {
          "primaryValues": [
            {
              "intValue": "150000"
            },
            {
              "intValue": "3200"
            },
            {
              "doubleValue": 450.75
            },
            {
              "doubleValue": 45.08
            }
          ]
        }
      ]
    }
  ],
  "runTime": "2026-08-05T12:00:00Z",
  "dateRanges": [
    {
      "startDate": {
        "year": 2026,
        "month": 7,
        "day": 6
      },
      "endDate": {
        "year": 2026,
        "month": 8,
        "day": 4
      }
    }
  ],
  "totalRowCount": 2,
  "nextPageToken": "QC7nzW91c2VTcGFubmVyQ29udGlubWF0aW6uVG9wZY45NP=="
}

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.results;

import com.google.api.services.curationpartners.v1.CurationPartners;
import com.google.api.services.curationpartners.v1.model.FetchReportResultRowsResponse;
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 FetchReportResultRows {

  /**
   * Executes the fetchRows operation for report result rows.
   *
   * @param curationPartnersClient the initialized Curation Partners API client.
   * @param accountId the account ID of the curator.
   * @param reportId the resource ID of the report.
   * @param resultId the resource ID of the report result.
   * @param pageSize the maximum number of rows to return per page.
   * @param pageToken the page token from a previous response, if any.
   * @throws IOException if the API returns an error.
   */
  public static void execute(
      CurationPartners curationPartnersClient,
      Long accountId,
      String reportId,
      String resultId,
      Integer pageSize,
      String pageToken)
      throws IOException {
    String name = String.format("curators/%s/reports/%s/results/%s", accountId, reportId, resultId);

    System.out.printf("Fetching report result rows for \"%s\".%n", name);

    CurationPartners.Curators.Reports.Results.FetchRows request =
        curationPartnersClient.curators().reports().results().fetchRows(name);

    if (pageSize != null) {
      request.setPageSize(pageSize);
    }
    if (pageToken != null) {
      request.setPageToken(pageToken);
    }

    FetchReportResultRowsResponse response = request.execute();

    System.out.println("Successfully fetched report result rows:");
    Utils.jsonPrettyPrint(response);
  }

  /**
   * Creates and configures the ArgumentParser for this sample.
   *
   * @return the configured ArgumentParser.
   */
  private static ArgumentParser createArgumentParser() {
    ArgumentParser parser =
        ArgumentParsers.newFor("FetchReportResultRows")
            .build()
            .defaultHelp(true)
            .description("Fetches rows for a completed report result.");

    // Required arguments.
    parser
        .addArgument("-a", "--account_id")
        .help("The account ID of the curator.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-r", "--report_id")
        .help("The resource ID of the report.")
        .required(true);
    parser
        .addArgument("--result_id")
        .help("The resource ID of the report result. This is identical to the resource ID of " +
            "the corresponding report run operation.")
        .required(true);

    // Optional arguments.
    parser
        .addArgument("--page_size")
        .help("The maximum number of rows to return per page.")
        .type(Integer.class);
    parser
        .addArgument("--page_token")
        .help("A page token, received from a previous `FetchReportResultRows` call.");

    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"),
          parsedArgs.getString("result_id"),
          parsedArgs.getInt("page_size"),
          parsedArgs.getString("page_token"));
    } catch (IOException ex) {
      System.out.printf("Curation Partners API returned error response:%n%s", ex);
      System.exit(1);
    }
  }
}

คุณระบุพารามิเตอร์การค้นหาต่อไปนี้ได้

  • pageSize: จำนวนแถวสูงสุดที่จะแสดงผล ค่าเริ่มต้นคือ 1,000 แถว และค่าสูงสุดคือ 10,000 แถว
  • pageToken: โทเค็นหน้าเว็บที่แสดงผลในการตอบกลับ fetchRows ก่อนหน้าเพื่อดึงแถวชุดถัดไป

การตอบกลับจะมีช่องต่อไปนี้

  • rows: อาร์เรย์ของออบเจ็กต์ Row แต่ละแถวจะมีข้อมูลต่อไปนี้
    • dimensionValues: ค่าสำหรับมิติข้อมูลที่ขอแต่ละรายการ โดยเรียงตามลำดับเดียวกับมิติข้อมูลในคำจำกัดความของรายงาน
    • metricValueGroups: กลุ่มค่าเมตริกที่สอดคล้องกับช่วงวันที่ แต่ละกลุ่มจะมีรายการ primaryValues ที่เรียงตามลำดับเดียวกับเมตริกในคำจำกัดความของรายงาน
  • dateRanges: ช่วงวันที่คงที่ที่คำนวณสำหรับรายงาน ช่อง dateRanges จะรวมอยู่ในเนื้อหาการตอบกลับของหน้าแรกเท่านั้น
  • totalRowCount: จำนวนแถวทั้งหมดในผลลัพธ์ของรายงาน ช่อง totalRowCount จะรวมอยู่ในเนื้อหาการตอบกลับของหน้าแรกเท่านั้น
  • nextPageToken: โทเค็นที่จะส่งในคำขอที่ตามมาเพื่อดึงแถวหน้าถัดไป หากไม่มีแถวเพิ่มเติม Curation Partners API จะไม่รวมช่องนี้ไว้ในเนื้อหาการตอบกลับ

ในตัวอย่าง REST ของ curators.reports.results.fetchRows แต่ละรายการใน rows จะแมปกับ ReportDefinition ที่กำหนดค่าไว้ในรายงานโดยตรง ดังนี้

  • dimensionValues: มีค่าที่สอดคล้องกับมิติข้อมูลแต่ละรายการในช่อง reportDefinition.dimensions ตามลำดับที่คุณระบุ ในตัวอย่าง ค่าแรก 2026-08-01 สอดคล้องกับมิติข้อมูล DATE และค่าที่ 2 segment-1001 สอดคล้องกับมิติข้อมูล CURATION_DATA_SEGMENT_ID
  • metricValueGroups: มีค่าเมตริกที่จัดกลุ่มตามช่วงวันที่ของรายงาน ในแต่ละกลุ่ม ช่อง primaryValues จะมีค่าที่สอดคล้องกับเมตริกแต่ละรายการในช่อง reportDefinition.metrics ตามลำดับที่คุณระบุ ในตัวอย่างนี้ ค่าทั้ง 4 ค่าสอดคล้องกับค่า enum Metric ต่อไปนี้

    • IMPRESSIONS: 150000
    • CLICKS: 3200
    • SPEND: 450.75
    • CURATION_PARTNER_FEE: 45.08
  • dateRanges: มีช่วงวันที่คงที่ที่ Google คำนวณสำหรับช่วงสัมพัทธ์ THIS_MONTH_TO_DATE ซึ่งกำหนดค่าไว้ในคำจำกัดความของรายงาน

ขั้นตอนถัดไป