事前準備 (v3)

設定

如要在資料記錄中註冊您的 Google Cloud 專案,請按照下列步驟操作:

  1. 前往 GCP 主控台
    如果您尚未設定 Google Cloud 專案,請務必建立專案
  2. 前往 GCP 資訊主頁中的 Cloud Talent Solution 專案設定。 如要查看導覽選單,請按一下左上角的三橫線圖示,並向下捲動,選取「Artificial Intelligence」(人工智慧) 下的「Talent Solution」

    從下拉式選單中選取專案。
  3. 如果這個 Google Cloud 專案還沒有相關聯的帳單帳戶,系統會提示您先設定一個帳單帳戶,然後將該帳戶連結到這個 Google Cloud 專案。請注意,只有 Google Cloud 專案的擁有者與帳單帳戶的擁有者可以連結這兩者。
    1. 按一下 [Enable billing] (啟用計費功能)

      「Enable billing for project」(啟用專案的計費功能) 對話方塊將會開啟。
    2. 按一下「建立帳單帳戶」。請參閱「建立、修改或關閉帳單帳戶」。
  4. 啟用 API
    按一下「啟用」

  5. 隨即顯示資訊主頁頁面。
    按一下「資料記錄」分頁標籤。

  6. 隨即顯示選擇接受資料記錄頁面。您必須接受此頁所列的條款,才能使用各項 API 功能。如不接受這些條款,您只能使用刪除 API 請求功能。

    按一下「啟用」

    系統隨即顯示確認頁面。
  7. 按一下確認頁面上的「繼續」


    隨即顯示「Connect service accounts」(連結服務帳戶) 畫面。

  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>
  

Python

如要進一步瞭解如何安裝及建立 Cloud Talent Solution 用戶端,請參閱 Cloud Talent Solution 用戶端程式庫

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

Node.js

如要進一步瞭解如何安裝及建立 Cloud Talent Solution 用戶端,請參閱 Cloud Talent Solution 用戶端程式庫

npm install 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)
	}
}