開始使用 Workflows API 適用的 Cloud 用戶端程式庫

說明如何開始使用 Workflows 適用的 Cloud 用戶端程式庫。

深入探索

如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:

程式碼範例

C++

在試用這個範例之前,請先按照C++使用用戶端程式庫的 Workflows 快速入門導覽課程中的設定說明操作。

如要向 Workflows 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

#include "google/cloud/workflows/v1/workflows_client.h"
#include "google/cloud/location.h"
#include <iostream>

int main(int argc, char* argv[]) try {
  if (argc != 3) {
    std::cerr << "Usage: " << argv[0] << " project-id location-id\n";
    return 1;
  }

  auto const location = google::cloud::Location(argv[1], argv[2]);

  namespace workflows = ::google::cloud::workflows_v1;
  auto client =
      workflows::WorkflowsClient(workflows::MakeWorkflowsConnection());

  for (auto w : client.ListWorkflows(location.FullName())) {
    if (!w) throw std::move(w).status();
    std::cout << w->DebugString() << "\n";
  }

  return 0;
} catch (google::cloud::Status const& status) {
  std::cerr << "google::cloud::Status thrown: " << status << "\n";
  return 1;
}

Node.js

const {WorkflowsClient} = require('@google-cloud/workflows');
const client = new WorkflowsClient();

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const location = 'us-central1';

async function listWorkflows(projectId, location) {
  const [workflows] = await client.listWorkflows({
    parent: client.locationPath(projectId, location),
  });
  for (const workflow of workflows) {
    console.info(`name: ${workflow.name}`);
  }
}

listWorkflows(projectId, location).catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

Node.js

import {WorkflowsClient} from '@google-cloud/workflows';
const client = new WorkflowsClient();

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const location = 'us-central1';

async function listWorkflows(projectId: string, location: string) {
  const [workflows] = await client.listWorkflows({
    parent: client.locationPath(projectId, location),
  });
  for (const workflow of workflows) {
    console.info(`name: ${workflow.name}`);
  }
}

listWorkflows(projectId, location).catch((err: Error) => {
  console.error(err.message);
  process.exitCode = 1;
});

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器