Mulai menggunakan Library Klien Cloud untuk Workflows API

Menunjukkan cara memulai Library Klien Cloud untuk Workflows.

Mempelajari lebih lanjut

Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:

Contoh kode

C++

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan C++ di Panduan memulai Workflows menggunakan library klien.

Untuk melakukan autentikasi ke Workflows, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

#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

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di Panduan memulai Workflows menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Node.js Workflows.

Untuk melakukan autentikasi ke Workflows, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di Panduan memulai Workflows menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Node.js Workflows.

Untuk melakukan autentikasi ke Workflows, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Langkah berikutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat Google Cloud browser contoh.