Perform sentiment analysis by using client libraries
This page shows you how to get started with the Cloud Natural Language API in your favorite programming language using the Google Cloud Client Libraries.
Before you begin
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Natural Language API:
gcloud services enable language.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Natural Language API:
gcloud services enable language.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
Install the client library
Go
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
Before installing the library, make sure you've prepared your environment for Node.js development.
npm install --save @google-cloud/language
Python
Before installing the library, make sure you've prepared your environment for Python development.
pip install --upgrade google-cloud-language
Analyze some text
Now you can use the Natural Language API to analyze some text. Run the following code to perform your first text sentiment analysis:
Go
Java
Node.js
Before running the example, make sure you've prepared your environment for Node.js development.
Python
Before running the example, make sure you've prepared your environment for Python development.
Congratulations! You've sent your first request to the Natural Language API.
How did it go?
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the Google Cloud project with the resources.
- Use the Google Cloud console to delete your project if you do not need it.
What's next
- Find out more about our Cloud Natural Language API Client Libraries.
- Consult the Natural Language Basics for conceptual information on forming Natural Language API requests and handling responses.
- Work through the Sentiment Analysis Tutorial and browse the Sample Applications.