Erste Schritte mit den Cloud-Clientbibliotheken für die Workflows API

Hier wird gezeigt, wie Sie mit den Cloud-Clientbibliotheken für Workflows beginnen.

Weitere Informationen

Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:

Codebeispiel

C++

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für C++ in der Workflows-Kurzanleitung zur Verwendung von Clientbibliotheken.

Richten Sie die Standardanmeldedaten für Anwendungen ein, um sich bei Workflows zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

#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

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für Node.js in der Workflows-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Workflows Node.js API.

Richten Sie die Standardanmeldedaten für Anwendungen ein, um sich bei Workflows zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Anleitung für die Einrichtung von Node.js in der Workflows-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Workflows Node.js API.

Richten Sie die Standardanmeldedaten für Anwendungen ein, um sich bei Workflows zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

Nächste Schritte

Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser fürGoogle Cloud verwenden.