Guia de início rápido: Como usar bibliotecas de cliente
Nesta página, mostramos como começar a usar a API Maintenance na sua linguagem de programação favorita.
Antes de começar
- Faça login na sua conta do Google Cloud . Se você começou a usar o Google Cloud, crie uma conta para avaliar o desempenho de nossos produtos em situações reais. Clientes novos também recebem US$ 300 em créditos para executar, testar e implantar cargas de trabalho.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Maintenance API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Maintenance API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.
Instale a biblioteca de cliente
C#
Para mais informações sobre a configuração do ambiente de desenvolvimento do C#, consulte o Guia de configuração do ambiente de desenvolvimento do C#.
Install-Package Google.Cloud.PubSub.V1 -Pre
Go
go get cloud.google.com/go/pubsub
Java
Para mais informações sobre a configuração do ambiente de desenvolvimento do Java, consulte o Guia de configuração do ambiente de desenvolvimento do Java.
Se você estiver usando o Maven,
adicione o código abaixo ao arquivo pom.xml. Para mais informações sobre
BOMs, consulte BOM das bibliotecas do Google Cloud Platform.
Se você estiver usando o Gradle, adicione isto às dependências:
Se você estiver usando o sbt, adicione o seguinte às suas dependências:
Se você estiver usando o Visual Studio Code ou o IntelliJ, poderá adicionar bibliotecas de cliente ao projeto usando estes plug-ins de IDE:
Os plug-ins também oferecem outras funcionalidades, como gerenciamento de chaves de contas de serviço. Consulte a documentação de cada plug-in para mais detalhes.
Node.js
Para mais informações sobre a configuração do ambiente de desenvolvimento do Node.js, consulte o guia de configuração do ambiente de desenvolvimento do Node.js.
npm install @google-cloud/pubsub
PHP
composer require google/cloud-pubsub
Python
Para mais informações sobre a configuração do ambiente de desenvolvimento do Python, consulte o Guia de configuração do ambiente de desenvolvimento do Python.
pip install --upgrade google-cloud-pubsub
Ruby
Para mais informações sobre a configuração do ambiente de desenvolvimento do Ruby, consulte o Guia de configuração do ambiente de desenvolvimento Ruby.
gem install google-cloud-pubsub
Fazer algo
Agora você pode usar o Unified Maintenance para fazer algo. Execute o código a seguir para realizar a primeira coisa:
C#
Para mais informações, consulte a documentação de referência da API Unified Maintenance C#.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
Go
Para mais informações, consulte a documentação de referência da API Unified Maintenance Go.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
Java
Para mais informações, consulte a documentação de referência da API Unified Maintenance Java.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
Node.js
Para mais informações, consulte a documentação de referência da API Unified Maintenance Node.js.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
PHP
Para mais informações, consulte a documentação de referência da API Unified Maintenance PHP.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
Python
Para mais informações, consulte a documentação de referência da API Unified Maintenance Python.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
Ruby
Para mais informações, consulte a documentação de referência da API Unified Maintenance Ruby.
Para autenticar no Unified Maintenance, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.
Como foi?
Limpar
Para evitar cobranças na sua Conta do Google pelos recursos usados neste guia de início rápido:
- Use o Google Cloud console para excluir o projeto, se você não precisar mais dele.
A seguir
Saiba mais sobre as bibliotecas de cliente da API Maintenance.