始める前に(v3)

設定

Google Cloud Platform プロジェクト(GCP プロジェクト)をデータロギングに登録するには、次の操作を行います。

  1. GCP Console に移動します。
    Google Cloud プロジェクトをまだセットアップしていない場合は、プロジェクトを作成する必要があります。
  2. GCP ダッシュボードで Cloud Talent Solution のプロジェクト設定に移動します。 ナビゲーションを表示するには、左上隅の三本線アイコンをクリックし、[人工知能] の下の [Talent Solution] を選択します。

    プルダウン メニューからプロジェクトを選択します。
  3. この Google Cloud プロジェクトにまだ課金アカウントを関連付けていない場合は、まず課金アカウントを設定し、そのアカウントをこの Google Cloud プロジェクトにリンクするように求められます。 リンクを実施できるのは Google Cloud プロジェクトの所有者であり、課金アカウントの所有者であるユーザーのみです。
    1. [課金を有効にする] をクリックする。

      [プロジェクトの請求の有効化] ダイアログ ボックスが表示されます。
    2. [請求先アカウントを作成] をクリックします。請求先アカウントの作成、変更、閉鎖をご覧ください。
  4. API を有効にします。
    [有効にする] をクリックします。

  5. ダッシュボード ページが表示されます。
    [データのロギング] タブをクリックします。

  6. データロギングを有効にするためのページが表示されます。 このページに記載されている条件に同意すると、さまざまな API 機能を使用できます。条件に同意しない場合は、API 削除リクエストしか使用できません。

    [有効にする] をクリックします。

    確認ページが表示されます。
  7. 確認ページで [続行] をクリックします。


    [サービス アカウントの接続] ビューが表示されます。

  8. サービス アカウントを接続する
    Google Cloud プロジェクト用のサービス アカウントを作成済みの場合は、ここに表示されます。それ以外の場合は、[サービス アカウントの管理] をクリックします。 手順については、サービス アカウントの作成をご覧ください。



    サービス アカウントを作成するときは、ボックス [新しい秘密鍵の提供] もオンにしてください。新しい JSON 認証情報ファイルが自動的にダウンロードされます。このファイルをサーバー上の特定の場所に保存します。手順に従って、このファイルを指すように GOOGLE_APPLICATION_CREDENTIALS 環境変数を設定します。これは Cloud Talent Solution に対するリクエストの認証に不可欠な手順です。

  9. サービス アカウントを作成したら、Cloud Talent Solution の左側のナビゲーション タブに戻ります。 先ほど作成したサービス アカウントが表示されます。 [接続] をクリックして、このアカウントを Cloud Talent Solution にリンクします。

  10. これでアカウントが接続されました。
    [完了] をクリックして次に進みます。

  11. 以上でシステムへの Cloud Talent Solution の統合を開始する準備ができました。

  12. 環境にプロジェクト ID を設定します。

    Linux または macOS

    export GOOGLE_CLOUD_PROJECT="your-project-id"

    Windows

    PowerShell を使用する場合:

    $env:GOOGLE_CLOUD_PROJECT="your-project-id"

    コマンド プロンプトを使用する場合:

    set GOOGLE_CLOUD_PROJECT="your-project-id"
  13. 次に、会社と求人の作成のクイックスタートに移動して Cloud Talent Solution の統合を開始します。

クライアント ライブラリをインストールする

Java

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。

Maven を使用している場合は、pom.xml ファイルに以下を追加します。

  <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-jobs</artifactId>
      <version>LATEST</version>
  </dependency>
  

Google Cloud Java クライアント ライブラリは現在 Android をサポートしていません。

Python

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。

pip install --upgrade google-api-python-client

Node.js

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。

npm install --save googleapis

Go

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。

go get google.golang.org/api/jobs/v3

リクエストを作成する

Java

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。


private static final JsonFactory JSON_FACTORY = new GsonFactory();
private static final NetHttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
private static final String DEFAULT_PROJECT_ID =
    "projects/" + System.getenv("GOOGLE_CLOUD_PROJECT");

private static CloudTalentSolution talentSolutionClient =
    createTalentSolutionClient(generateCredential());

private static CloudTalentSolution createTalentSolutionClient(GoogleCredentials credential) {
  String url = "https://jobs.googleapis.com";

  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  return new CloudTalentSolution.Builder(NET_HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("JobServiceClientSamples")
      .setRootUrl(url)
      .build();
}

private static GoogleCredentials generateCredential() {
  try {
    // Credentials could be downloaded after creating service account
    // set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable, for example:
    // export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/key.json
    return GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(CloudTalentSolutionScopes.JOBS));
  } catch (Exception e) {
    System.out.println("Error in generating credential");
    throw new RuntimeException(e);
  }
}

public static CloudTalentSolution getTalentSolutionClient() {
  return talentSolutionClient;
}

public static void main(String... args) throws Exception {
  try {
    ListCompaniesResponse listCompaniesResponse =
        talentSolutionClient.projects().companies().list(DEFAULT_PROJECT_ID).execute();
    System.out.println("Request Id is " + listCompaniesResponse.getMetadata().getRequestId());
    if (listCompaniesResponse.getCompanies() != null) {
      for (Company company : listCompaniesResponse.getCompanies()) {
        System.out.println(company.getName());
      }
    }
  } catch (IOException e) {
    System.out.println("Got exception while listing companies");
    throw e;
  }
}

Python

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。

import os

from googleapiclient.discovery import build
from googleapiclient.errors import Error

client_service = build("jobs", "v3")

def run_sample():
    try:
        project_id = "projects/" + os.environ["GOOGLE_CLOUD_PROJECT"]
        response = (
            client_service.projects().companies().list(parent=project_id).execute()
        )
        print("Request Id: %s" % response.get("metadata").get("requestId"))
        print("Companies:")
        if response.get("companies") is not None:
            for company in response.get("companies"):
                print("%s" % company.get("name"))
        print("")

    except Error as e:
        print("Got exception while listing companies")
        raise e

if __name__ == "__main__":
    run_sample()

Go

Cloud Talent Solution クライアントのインストールと作成の詳細については、Cloud Talent Solution クライアント ライブラリをご覧ください。


// Command quickstart is an example of using the Google Cloud Talent Solution API.
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"golang.org/x/oauth2/google"
	talent "google.golang.org/api/jobs/v3"
)

func main() {
	projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
	parent := fmt.Sprintf("projects/%s", projectID)

	// Authorize the client using Application Default Credentials.
	// See https://g.co/dv/identity/protocols/application-default-credentials
	ctx := context.Background()
	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		log.Fatal(err)
	}

	// Create the jobs service client.
	ctsService, err := talent.New(client)
	if err != nil {
		log.Fatal(err)
	}

	// Make the RPC call.
	response, err := ctsService.Projects.Companies.List(parent).Do()
	if err != nil {
		log.Fatalf("Failed to list Companies: %v", err)
	}

	// Print the request id.
	fmt.Printf("Request ID: %q\n", response.Metadata.RequestId)

	// Print the returned companies.
	for _, company := range response.Companies {
		fmt.Printf("Company: %q\n", company.Name)
	}
}