使用客户端库执行情感分析
本页向您介绍如何借助 Google Cloud 客户端库以您偏好的编程语言开始使用 Cloud Natural Language API。
准备工作
-
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
安装客户端库
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
在安装库之前,请确保已经为 Node.js 开发准备好环境。
npm install --save @google-cloud/language
Python
在安装库之前,请确保已经为 Python 开发准备好环境。
pip install --upgrade google-cloud-language
分析一些文本
现在您可以使用 Natural Language API 来分析一些文本。请运行以下代码以执行您的第一次文本情感分析:
恭喜!您已向 Natural Language API 发送了第一个请求。
结果怎么样?
清理
为避免因本页面中使用的资源导致您的 Google Cloud 账号产生费用,请删除包含这些资源的 Google Cloud 项目。
- 使用 Google Cloud 控制台删除不需要的项目。
后续步骤
- 详细了解我们的 Cloud Natural Language API 客户端库。
- 查阅 Natural Language 基础知识,了解有关形成 Natural Language API 请求和处理响应的概念信息。
- 通读情感分析教程并浏览示例应用。