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.
-
Set up a Cloud Console project.
Click to:
- Create or select a project.
- Enable the Google Natural Language API for that project.
- Create a service account.
- Download a private key as JSON.
You can view and manage these resources at any time in the Cloud Console.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.
Install the client library
C#
Install-Package Google.Cloud.Language.V1 -Pre
Go
go get -u 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 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
PHP
composer require google/cloud
Python
Before installing the library, make sure you've prepared your environment for Python development.
pip install --upgrade google-cloud-language
Ruby
gem install 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:
C#
Go
Java
Node.js
Before running the example, make sure you've prepared your environment for Node.js development.
PHP
Python
Before running the example, make sure you've prepared your environment for Python development.
Ruby
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 in this quickstart, follow these steps.
- Use the 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.