本指南提供開始使用 Natural Language 的所有必要設定步驟。
關於 Google Cloud 控制台
Google Cloud 控制台是一個網頁版 UI,可用於佈建、設定、管理和監控使用 Google Cloud 產品的系統。您可以使用 Google Cloud 控制台來設定及管理 Natural Language 資源。
建立專案
如要使用 Google Cloud 提供的服務,您必須建立專案。
專案會統整所有 Google Cloud 資源。專案包含下列元件:
- 一組協作者
- 已啟用的 API (和其他資源)
- 監控工具
- 取得專案的
- 驗證和存取權控管
您可以建立一個專案,也可以建立多個專案,並使用這些專案在資源階層中整理您的 Google Cloud 資源。如要進一步瞭解專案,請參閱 Resource Manager 說明文件。
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.
啟用 API
您必須為專案啟用 Cloud Natural Language API。如要進一步瞭解如何啟用 API,請參閱服務使用情形說明文件。
Enable the Cloud Natural Language API.
安裝並初始化 gcloud CLI
如果您打算使用 Natural Language API,則必須安裝並初始化 gcloud CLI。gcloud CLI 是一套工具,可用來管理託管於 Google Cloud 的資源和應用程式。包括 gcloud CLI。 以下連結提供操作說明:
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
設定驗證方法
任何使用該 API 的用戶端應用程式都必須經過驗證,並獲得所要求資源的存取權。驗證設定方式取決於您是在本機開發環境中作業,還是設定實際工作環境。詳情請參閱「設定應用程式預設憑證」。
Select the tabs for how you plan to access the API:
gcloud
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
用戶端程式庫
如要在本機開發環境中使用用戶端程式庫,請安裝並初始化 gcloud CLI,然後使用您的使用者憑證設定應用程式預設憑證。
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
REST
如要在本機開發環境中使用 REST API,請使用您提供給 gcloud CLI 的憑證。
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
如要瞭解如何為正式版環境設定驗證,請參閱 Google Cloud 驗證說明文件中的 Set up Application Default Credentials for code running on Google Cloud。
安裝 Natural Language API 用戶端程式庫
您可以透過三種方式呼叫 Natural Language API:
- Google 支援的用戶端程式庫 (建議)
- REST
- gRPC
我們提供多種常見語言的用戶端程式庫。如要瞭解如何安裝用戶端程式庫,請參閱 Cloud Natural Language 用戶端程式庫。
關於角色
存取 Cloud Natural Language API 並不需要任何角色。無論權限為何,經過驗證的使用者或應用程式都可以呼叫 API。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-24 (世界標準時間)。