ดูรายงาน

การดูรายงานจะดึงรายละเอียดการกำหนดค่าของเทมเพลต Report ที่สร้างขึ้นสำหรับบัญชีผู้ดูแลเนื้อหา

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

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

คุณต้อง ตั้งค่าการตรวจสอบสิทธิ์ก่อนดำเนินการต่อ

ดูรายงานแต่ละฉบับ

หากต้องการดูรายละเอียดของรายงานที่เฉพาะเจาะจง ให้ใช้ curators.reports.get เมธอด

ตัวอย่างต่อไปนี้จะส่งคำขอ GET เพื่อดึงข้อมูลรายงานตามชื่อทรัพยากร

REST

ส่งคำขอ

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

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

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

คำตอบ

{
  "name": "curators/ACCOUNT_ID/reports/123456789",
  "reportId": "123456789",
  "displayName": "Updated Data Segment Performance",
  "reportDefinition": {
    "dimensions": [
      "DATE",
      "CURATION_DATA_SEGMENT_ID"
    ],
    "metrics": [
      "IMPRESSIONS",
      "CLICKS",
      "SPEND",
      "CURATION_PARTNER_FEE"
    ],
    "dateRange": {
      "relative": "THIS_MONTH_TO_DATE"
    },
    "timeZoneSource": "UTC"
  },
  "createTime": "2026-08-01T10:00:00Z",
  "updateTime": "2026-08-01T10:10:00Z",
  "locale": "en"
}

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.Report;
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 GetReport {

  /**
   * Executes the get 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 retrieve.
   * @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("Get report with name \"%s\".%n", name);

    // Get the specified report.
    Report report = curationPartnersClient.curators().reports().get(name).execute();

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

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

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

ดูรายการรายงาน

หากต้องการดูรายงาน ให้ใช้ curators.reports.list เมธอด

ตัวอย่างต่อไปนี้จะส่งคำขอ GET เพื่อแสดงรายการรายงานทั้งหมดสำหรับบัญชีผู้ดูแลเนื้อหา

REST

ส่งคำขอ

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

คำตอบ

{
  "reports": [
    {
      "name": "curators/ACCOUNT_ID/reports/123456789",
      "reportId": "123456789",
      "displayName": "Updated Data Segment Performance",
      "reportDefinition": {
        "dimensions": [
          "DATE",
          "CURATION_DATA_SEGMENT_ID"
        ],
        "metrics": [
          "IMPRESSIONS",
          "CLICKS",
          "SPEND",
          "CURATION_PARTNER_FEE"
        ],
        "dateRange": {
          "relative": "THIS_MONTH_TO_DATE"
        },
        "timeZoneSource": "UTC"
      },
      "createTime": "2026-08-01T10:00:00Z",
      "updateTime": "2026-08-01T10:10:00Z",
      "locale": "en"
    },
    {
      "name": "curators/ACCOUNT_ID/reports/987654321",
      "reportId": "987654321",
      "displayName": "Curated Package Performance",
      "reportDefinition": {
        "dimensions": [
          "DATE",
          "DEAL_ID"
        ],
        "metrics": [
          "IMPRESSIONS",
          "SPEND"
        ],
        "dateRange": {
          "relative": "THIS_MONTH_TO_DATE"
        },
        "timeZoneSource": "UTC"
      },
      "createTime": "2026-08-02T15:20:00Z",
      "updateTime": "2026-08-02T15:20:00Z",
      "locale": "en"
    }
  ],
  "nextPageToken": "RG9ybW91c2VTcGFubmVyQ29udGludWF0aW9uVG9rZW46MQ=="
}

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.ListReportsResponse;
import com.google.api.services.curationpartners.v1.model.Report;
import com.google.api.services.samples.curationpartners.v1.Utils;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
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 ListReports {

  /**
   * Executes the list operation for reports.
   *
   * @param curationPartnersClient the initialized Curation Partners API client.
   * @param accountId the account ID of the curator whose reports to list.
   * @param pageSize the maximum number of items to return per page.
   * @param pageToken the page token from a previous response, if any.
   * @param filter a filter expression.
   * @param orderBy an order by expression.
   * @throws IOException if the API returns an error.
   */
  public static void execute(
      CurationPartners curationPartnersClient,
      Long accountId,
      Integer pageSize,
      String pageToken,
      String filter,
      String orderBy)
      throws IOException {
    String parent = String.format("curators/%s", accountId);

    System.out.printf("Listing reports for curator account \"%s\".%n", parent);

    CurationPartners.Curators.Reports.List request =
        curationPartnersClient.curators().reports().list(parent);

    if (pageSize != null) {
      request.setPageSize(pageSize);
    }
    if (pageToken != null) {
      request.setPageToken(pageToken);
    }
    if (filter != null) {
      request.setFilter(filter);
    }
    if (orderBy != null) {
      request.setOrderBy(orderBy);
    }

    ListReportsResponse response = request.execute();
    List<Report> reports = response.getReports();

    if (reports == null || reports.isEmpty()) {
      System.out.println("No reports found.");
      return;
    }

    System.out.println("Successfully listed reports:");
    for (Report report : reports) {
      Utils.jsonPrettyPrint(report);
      System.out.println();
    }

    if (response.getNextPageToken() != null) {
      System.out.printf("Next page token: %s%n", response.getNextPageToken());
    }
  }

  /**
   * Creates and configures the ArgumentParser for this sample.
   *
   * @return the configured ArgumentParser.
   */
  private static ArgumentParser createArgumentParser() {
    ArgumentParser parser =
        ArgumentParsers.newFor("ListReports")
            .build()
            .defaultHelp(true)
            .description("Lists reports for the specified curator account.");

    // Required arguments.
    parser
        .addArgument("-a", "--account_id")
        .help("The account ID of the curator whose reports to list.")
        .required(true)
        .type(Long.class);

    // Optional arguments.
    parser
        .addArgument("--page_size")
        .help("The maximum number of reports to return per page.")
        .type(Integer.class);
    parser
        .addArgument("--page_token")
        .help("A page token, received from a previous `ListReports` call.");
    parser
        .addArgument("--filter")
        .help("An optional parameter used to filter the reports returned. Uses Cloud API list " +
            "filtering syntax. To learn more, see:" +
            "https://developers.google.com/ad-manager/api/beta/filters");
    parser
        .addArgument("--order_by")
        .help("An expression to order the results by. To learn more, see: " +
            "https://developers.google.com/ad-manager/api/beta/filters#order");

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

หากต้องการควบคุมเอาต์พุตรายการ ให้ใช้พารามิเตอร์การค้นหาที่ไม่บังคับต่อไปนี้

  • pageSize: จำนวนรายงานสูงสุดที่จะแสดงต่อหน้า
  • pageToken: โทเค็นที่ได้รับจากการตอบกลับ list ก่อนหน้าเพื่อดึงข้อมูลรายงานหน้าถัดไป
  • filter: นิพจน์สำหรับการกรองผลลัพธ์
  • orderBy: นิพจน์สำหรับการจัดลำดับผลลัพธ์

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