クライアント ライブラリを使用したドキュメント処理
このページでは、使い慣れたプログラミング言語で Document AI API を使用する方法について説明します。
始める前に
- 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 Document AI 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.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click 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 Document AI 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.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click 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.
クライアント ライブラリをインストールする
C#
C# 開発環境の設定の詳細については、C# 開発環境設定ガイドをご覧ください。
Install-Package Google.Cloud.DocumentAI.V1 -Pre
Go
go get cloud.google.com/go/documentai
Java
Java 開発環境の設定の詳細については、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 開発環境の設定の詳細については、Node.js 開発環境設定ガイドをご覧ください。
npm install @google-cloud/documentai
PHP
composer require google/cloud-document-ai
Python
Python 開発環境の設定の詳細については、Python 開発環境設定ガイドをご覧ください。
pip install --upgrade google-cloud-documentai
Ruby
Ruby 開発環境の設定の詳細については、Ruby 開発環境設定ガイドをご覧ください。
gem install google-cloud-document_ai
ドキュメント処理
Document AI API を使用して、ローカルの PDF ドキュメントから情報をリクエストします。次のサンプルを実行するには、まず UI でプロセッサを作成する必要があります。
Console
Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。
[
Create processor] を選択します。作成するプロセッサの種類をリストからクリックします。
サイドの [プロセッサを作成] ウィンドウで、プロセッサ名を指定します。
リストからリージョンを選択します。
[作成] をクリックして、プロセッサを作成します。
プロセッサを作成してプロセッサ ID を取得したら、次のコードを実行して個々のドキュメントの処理をリクエストします。
C#
詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
C++
詳細については、Document AI C++ API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Go
詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Java
詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Node.js
詳細については、Document AI Node.js API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
PHP
詳細については、Document AI PHP API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Ruby
詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
いかがでしたか
クリーンアップ
このクイックスタートで使用したリソースについて、Google アカウントに課金されないようにするには、次の手順を行います。
- プロジェクトを必要としない場合は、Google Cloud コンソール を使用して削除してください。
次のステップ
Document AI API クライアント ライブラリの詳細を確認する。