Cloud Tasks Client Libraries

This page shows how to get started with the Cloud Client Libraries for the Cloud Tasks API. Read more about the client libraries for Cloud APIs in Client Libraries Explained.

Installing the client library

C#

For more information, see Setting Up a C# Development Environment.

Install-Package Google.Cloud.Tasks.V2 -Version 1.0.0

Go

For more information, see Setting Up Your Development Environment.

go get -u cloud.google.com/go/tasks

Java

For more information, see Setting Up a Java Development Environment.

If you are using Maven, add the following to your pom.xml file:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-tasks</artifactId>
  <version>1.29.1</version>
</dependency>

If you are using Gradle, add the following to your dependencies:

compile 'com.google.cloud:google-cloud-tasks:1.29.1'

If you are using SBT, add the following to your dependencies:

libraryDependencies += "com.google.cloud" % "google-cloud-tasks" % "1.29.1"

If you are using IntelliJ or Eclipse, you can add client libraries to your project using the following IDE plugins:

The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.

Node.js

For more information, see Setting Up a Node.js Development Environment.

npm install --save @google-cloud/tasks

PHP

composer require google/cloud-tasks

Python

For more information, see Setting Up a Python Development Environment.

pip install --upgrade google-cloud-tasks

Ruby

For more information, see Setting Up a Ruby Development Environment.

gem install google-cloud-tasks

Setting up authentication for use with the client library

To run the client library, you must first set up authentication by creating a service account with its key, and then setting an environment variable to point to that key. For more information, see the GCP authentication documentation .

Cloud Console

创建服务帐号:

  1. 在 Cloud Console 中,转到创建服务帐号页面。

    转到“创建服务帐号”
  2. 选择一个项目。
  3. 服务帐号名称字段中,输入一个名称。 Cloud Console 会根据此名称填充服务帐号 ID 字段。

    服务帐号说明字段中,输入说明。例如,Service account for quickstart

  4. 点击创建
  5. 点击选择角色字段。

    快速访问下,点击基本,然后点击所有者

  6. 点击继续
  7. 点击完成以完成服务帐号的创建过程。

    不要关闭浏览器窗口。您将在下一步骤中用到它。

创建服务帐号密钥:

  1. 在 Cloud Console 中,点击您创建的服务帐号的电子邮件地址。
  2. 点击密钥
  3. 依次点击添加密钥创建新密钥
  4. 点击创建。JSON 密钥文件将下载到您的计算机上。
  5. 点击关闭

命令行

您可以使用本地机器上的 Cloud SDK 或在 Cloud Shell 中运行以下命令。

  1. 创建服务帐号。将 NAME 替换为服务帐号的名称。

    gcloud iam service-accounts create NAME
  2. 向服务帐号授予权限。将 PROJECT_ID 替换为您的项目 ID。

    gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:NAME@PROJECT_ID.iam.gserviceaccount.com" --role="roles/owner"
  3. 生成密钥文件。将 FILE_NAME 替换为密钥文件的名称。

    gcloud iam service-accounts keys create FILE_NAME.json --iam-account=NAME@PROJECT_ID.iam.gserviceaccount.com

将环境变量 GOOGLE_APPLICATION_CREDENTIALS 设置为包含您的服务帐号密钥的 JSON 文件的路径。 此变量仅适用于当前的 shell 会话,因此,如果您打开新的会话,请重新设置该变量。

Using the client library

For examples of using the client library, see Creating HTTP Target Tasks or Creating App Engine Tasks

Additional resources