Guía de inicio rápido: Cómo usar bibliotecas cliente
En esta página, se muestra cómo comenzar a usar la API de Cloud Natural Language en el lenguaje de programación de tu preferencia con las bibliotecas cliente de Google Cloud.
Antes de comenzar
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Natural Language API.
-
Create a service account:
-
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.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
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_CREDENTIALS
to 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.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Natural Language API.
-
Create a service account:
-
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.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
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_CREDENTIALS
to 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.
Instala la biblioteca cliente
Comienza a usarlo
go get cloud.google.com/go/language/apiv1
Java
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, 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
Antes de instalar la biblioteca, asegúrate de haber preparado tu entorno para el desarrollo en Node.js.
npm install --save @google-cloud/language
Python
Antes de instalar la biblioteca, asegúrate de haber preparado tu entorno para el desarrollo en Python.
pip install --upgrade google-cloud-language
Analizar un texto
Ahora puedes usar la API de Natural Language para analizar un texto. Ejecuta el siguiente código para realizar tu primer análisis de opiniones de texto:
Go
Java
Node.js
Antes de ejecutar el ejemplo, asegúrate de haber preparado tu entorno para el desarrollo en Node.js.
Python
Antes de ejecutar el ejemplo, asegúrate de haber preparado tu entorno para el desarrollo en Python.
¡Felicitaciones! Enviaste tu primera solicitud a la API de Natural Language.
¿Cómo fue?
Limpia
Sigue estos pasos para evitar que se apliquen cargos a tu cuenta de Google Cloud por los recursos que usaste en esta página.
- Usa Cloud Console para borrar tu proyecto si no lo necesitas.
¿Qué sigue?
- Obtén más información sobre nuestras las bibliotecas cliente de la API de Cloud Natural Language.
- Consulta los Conceptos básicos de Natural Language para obtener información conceptual sobre la formación de solicitudes de la API de Natural Language y manejar respuestas.
- Revisa con atención el Instructivo de análisis de opiniones y explora las Aplicaciones de muestra.