Enterprise Knowledge Graph API を設定する

このガイドでは、Enterprise Knowledge Graph の使用を開始するために必要なすべての設定手順を説明します。

Google Cloud コンソールについて

Google Cloud console は、 Google Cloud プロダクトを使用するシステムのプロビジョニング、構成、管理、モニタリングに使用されるウェブ UI です。 Google Cloud コンソールを使用して、Enterprise Knowledge Graph リソースを設定および管理します。

プロジェクトを作成する

Google Cloudが提供するサービスを使用するには、プロジェクトを作成する必要があります。

プロジェクトはすべての Google Cloud リソースを整理します。プロジェクトは、次のコンポーネントから構成されます。

  • 共同編集者
  • 有効な API とその他のリソース
  • モニタリング ツール
  • お支払い情報
  • 認証とアクセス制御

1 つのプロジェクトを作成することも、複数のプロジェクトを作成することもできます。プロジェクトを使用して、リソース階層内で Google Cloud リソースを整理することもできます。プロジェクトの詳細については、Resource Manager のドキュメントをご覧ください。

In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

Roles required to select or create a project

  • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
  • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

Go to project selector

API を有効にする

プロジェクトで Enterprise Knowledge Graph API を有効にする必要があります。API の有効化の詳細については、Service Usage のドキュメントをご覧ください。

Enable the Enterprise Knowledge Graph API.

Roles required to enable APIs

To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

Enable the API

認証を設定する

API を使用するクライアント アプリケーションはすべて、認証の対象であり、リクエストされるリソースへのアクセス権が付与されている必要があります。このセクションでは、認証の重要なコンセプトと設定手順について説明します。詳細については、認証の概要をご覧ください。

サービス アカウントについて

認証には複数のオプションがありますが、認証とアクセス制御にサービス アカウントを使用することをおすすめします。サービス アカウントでは、エンドユーザーではなく、アプリケーションの認証情報が提供されます。プロジェクトはサービス アカウントを所有しています。1 つのプロジェクトに対して複数のサービス アカウントを作成できます。詳しくは、サービス アカウントをご覧ください。

ロールについて

API を呼び出す場合、 Google Cloud では、適切な権限のある呼び出し側の ID(該当するユーザー、エンティティ、プロセスまたは定義済みの属性)が必要になります。権限を付与するには、サービス アカウントにロールを付与します。詳細については、Identity and Access Management(IAM)のドキュメントをご覧ください。

Enterprise Knowledge Graph API を試すには、次の手順で [プロジェクト] > [オーナー] のロールを使用できます。[プロジェクト] > [オーナー] のロールを設定すると、サービス アカウントにプロジェクト内のリソースに対する完全な権限が付与されます。サービス アカウントに完全な権限が必要ない場合は、Google Cloud コンソールを使用してより制限されたロールを指定します。Enterprise Knowledge Graph の権限とロールの一覧については、Enterprise Knowledge Graph の権限Enterprise Knowledge Graph のロールをご覧ください。IAM ロールを使用して権限を管理する方法については、サービス アカウントへのロールの付与をご覧ください。

サービス アカウントキーについて

サービス アカウントは、1 つまたは複数の公開鍵または秘密鍵のペアに関連付けられます。新しい鍵ペアを作成すると、秘密鍵がダウンロードされます。API の呼び出し時に、Google Cloud CLI は秘密鍵を使用して認証情報を生成します。

サービス アカウントを作成し、秘密鍵ファイルをダウンロードする

Create a service account:

  1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
  2. In the Google Cloud console, go to the Create service account page.

    Go to Create service account
  3. Select your project.
  4. 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.

  5. Click Create and continue.
  6. Grant the Project > Owner role to the service account.

    To grant the role, find the Select a role list, then select Project > Owner.

  7. Click Continue.
  8. 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:

  1. In the Google Cloud console, click the email address for the service account that you created.
  2. Click Keys.
  3. Click Add key, and then click Create new key.
  4. Click Create. A JSON key file is downloaded to your computer.
  5. Click Close.

環境でサービス アカウント キー ファイルを使用する

Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS. This variable applies only to your current shell session. If you want the variable to apply to future shell sessions, set the variable in your shell startup file, for example in the ~/.bashrc or ~/.profile file.

Linux または macOS

export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

Replace KEY_PATH with the path of the JSON file that contains your credentials.

For example:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

Windows

For PowerShell:

$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

Replace KEY_PATH with the path of the JSON file that contains your credentials.

For example:

$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"

For command prompt:

set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH

Replace KEY_PATH with the path of the JSON file that contains your credentials.