Workflows API 的 Cloud 客户端库使用入门
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
演示如何开始使用 Workflows 的 Cloud 客户端库。
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[],[],null,["# Get started with the Cloud Client Libraries for the Workflows API\n\nDemonstrates getting started with the Cloud Client Libraries for Workflows.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Workflows client libraries](/workflows/docs/reference/libraries)\n\nCode sample\n-----------\n\n### C++\n\n\nBefore trying this sample, follow the C++ setup instructions in the\n[Workflows quickstart using\nclient libraries](/workflows/docs/quickstart-client-libraries).\n\n\nTo authenticate to Workflows, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n #include \"google/cloud/workflows/v1/workflows_client.h\"\n #include \"google/cloud/location.h\"\n #include \u003ciostream\u003e\n\n int main(int argc, char* argv[]) try {\n if (argc != 3) {\n std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" project-id location-id\\n\";\n return 1;\n }\n\n auto const location = google::cloud::Location(argv[1], argv[2]);\n\n namespace workflows = ::google::cloud::workflows_v1;\n auto client =\n workflows::WorkflowsClient(workflows::MakeWorkflowsConnection());\n\n for (auto w : client.ListWorkflows(location.FullName())) {\n if (!w) throw std::move(w).status();\n std::cout \u003c\u003c w-\u003eDebugString() \u003c\u003c \"\\n\";\n }\n\n return 0;\n } catch (google::cloud::Status const& status) {\n std::cerr \u003c\u003c \"google::cloud::Status thrown: \" \u003c\u003c status \u003c\u003c \"\\n\";\n return 1;\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Workflows quickstart using\nclient libraries](/workflows/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Workflows Node.js API\nreference documentation](https://googleapis.dev/nodejs/workflows/latest/).\n\n\nTo authenticate to Workflows, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const {WorkflowsClient} = require('@google-cloud/workflows');\n const client = new WorkflowsClient();\n\n /**\n * TODO(developer): Uncomment these variables before running the sample.\n */\n // const projectId = 'my-project';\n // const location = 'us-central1';\n\n async function listWorkflows(projectId, location) {\n const [workflows] = await client.listWorkflows({\n parent: client.locationPath(projectId, location),\n });\n for (const workflow of workflows) {\n console.info(`name: ${workflow.name}`);\n }\n }\n\n listWorkflows(projectId, location).catch(err =\u003e {\n console.error(err.message);\n process.exitCode = 1;\n });\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Workflows quickstart using\nclient libraries](/workflows/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Workflows Node.js API\nreference documentation](https://googleapis.dev/nodejs/workflows/latest/).\n\n\nTo authenticate to Workflows, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import {WorkflowsClient} from '@google-cloud/workflows';\n const client = new WorkflowsClient();\n\n /**\n * TODO(developer): Uncomment these variables before running the sample.\n */\n // const projectId = 'my-project';\n // const location = 'us-central1';\n\n async function listWorkflows(projectId: string, location: string) {\n const [workflows] = await client.listWorkflows({\n parent: client.locationPath(projectId, location),\n });\n for (const workflow of workflows) {\n console.info(`name: ${workflow.name}`);\n }\n }\n\n listWorkflows(projectId, location).catch((err: Error) =\u003e {\n console.error(err.message);\n process.exitCode = 1;\n });\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=workflows)."]]