執行報表

執行報表會啟動現有Report範本,產生 Curation 帳戶的成效資料。

本指南說明如何使用 Curation Partners API 執行 Report 範本,產生說明收錄帳戶成效的報表。

事前準備

繼續操作前,請先完成下列事項:

啟動報表執行作業

如要執行現有報表,請使用 curators.reports.run 方法。

以下範例會發出 POST 要求,啟動報表執行作業:

REST

要求

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

更改下列內容:

  • ACCOUNT_ID:您的帳戶 ID。
  • ACCESS_TOKEN:存取權杖。

回應

{
  "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);
    }
  }
}

執行報表是一項非同步長時間執行的作業。呼叫 run 方法時,Curation Partners API 會傳回 Operation 資源。作業的 name 欄位會識別執行作業,格式如下:

curators/ACCOUNT_ID/reports/REPORT_ID/operations/OPERATION_ID

傳回的 Operation 物件包含下列項目:

  • name:伺服器指派給長時間執行的作業的名稱。
  • metadata:服務專屬的進度資訊 (選用)。您在 curators.reports.run 回應中收到的 Operation 物件可能不會填入 metadata 欄位。

啟動報表執行作業後,您必須等到作業的 done 欄位為 true 值,才能查看報表結果。報表執行完成所需的時間長度,取決於報表的複雜度。

後續步驟