用戶群基本資訊

用戶群是獲他人指派任何職缺和公司物件的實體。用戶群會在 Google Cloud 專案和您上傳的資料間建立組織的中間層級。用戶群可藉由用戶群限制避免資料分享,因此不需建立多個專案即可將不同的資料群組區隔開來。如果須支援多個客戶且不希望客戶間共享資料,但是又希望能使用單一 Google Cloud專案來進行計費與產出報告,則維持多個用戶群會很有用。例如:

  • 人才招募網站供應商為旗下有多個子公司的機構建構人才招募網站。
  • 聘僱代理機構為多個企業建構工作申請者追蹤系統。

系統會為每個 Google Cloud 專案指派單一預設用戶群的 tenant_id。您也可以選擇在指定專案中建立多個用戶群來變更預設值。

用戶群彼此間是完全隔離的。所有 API 僅要求一個單一用戶群,即可避免在單個 API 呼叫中跨多個用戶群查詢資料。機器學習 (ML) 同樣會將用戶群視為獨立單位,不會跨越用戶群限制。專案可以根據需要支援所需的用戶群數量。

預設用戶群

在職缺搜尋 v4 和更新的版本中,用戶群實體為必要項目。系統會將單一預設用戶群的 tenant_id 指派給所有專案。如果您不想使用多用戶群,您可以:

  1. 使用專案的預設用戶群 (推薦)。您不需參照特定用戶群即可執行此操作。您可以使用格式 projects/{project_id}/jobs/{job_id},Cloud Talent Solution 後端會假設您使用的是預設用戶群。

  2. 建立單一用戶群並以其代替預設用戶群。如果要建立自己的用戶群,則需要參照其為:projects/{project_id}/tenants/{tenant_id}/jobs/{job_id}

預設的 tenant_id 在每個專案都是不重複的,就算建立了其他的用戶群也永遠不會遭到覆寫或取代。您無法在預設用戶群上呼叫 CRUD 方法。

建立的用戶群 (可選)

建立自己的用戶群是選擇性的。CTS 後端會為每個職缺搜尋專案指派一個預設用戶群。如果您不想使用多用戶群來分隔資料的子分割,建議您使用預設的用戶群。

建立用戶群

您需要建立不重複的 externalId 值並將其指派給新的用戶群。呼叫則會傳回由後端系統指派的不重複 name,同時也會指派給該用戶群。請務必記錄並儲存 nameexternalId 值,因為系統會使用這些名稱來進行更新/刪除/參照。

下列程式碼示範新用戶群的建立:

Java

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Java API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.talent.v4.CreateTenantRequest;
import com.google.cloud.talent.v4.ProjectName;
import com.google.cloud.talent.v4.Tenant;
import com.google.cloud.talent.v4.TenantServiceClient;
import java.io.IOException;

public class JobSearchCreateTenant {

  public static void createTenant() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String externalId = "your-external-id";
    createTenant(projectId, externalId);
  }

  // Create Tenant for scoping resources, e.g. companies and jobs.
  public static void createTenant(String projectId, String externalId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      ProjectName parent = ProjectName.of(projectId);
      Tenant tenant = Tenant.newBuilder().setExternalId(externalId).build();

      CreateTenantRequest request =
          CreateTenantRequest.newBuilder().setParent(parent.toString()).setTenant(tenant).build();

      Tenant response = tenantServiceClient.createTenant(request);
      System.out.println("Created Tenant");
      System.out.format("Name: %s%n", response.getName());
      System.out.format("External ID: %s%n", response.getExternalId());
    }
  }
}

Node.js

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Node.js API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


const talent = require('@google-cloud/talent').v4;

/** Create Tenant for scoping resources, e.g. companies and jobs */
function sampleCreateTenant(projectId, externalId) {
  const client = new talent.TenantServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const externalId = 'Your Unique Identifier for Tenant';
  const formattedParent = client.projectPath(projectId);
  const tenant = {
    externalId: externalId,
  };
  const request = {
    parent: formattedParent,
    tenant: tenant,
  };
  client
    .createTenant(request)
    .then(responses => {
      const response = responses[0];
      console.log('Created Tenant');
      console.log(`Name: ${response.name}`);
      console.log(`External ID: ${response.externalId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Python API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


from google.cloud import talent


def create_tenant(project_id, external_id):
    """Create Tenant for scoping resources, e.g. companies and jobs"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # external_id = 'Your Unique Identifier for Tenant'

    if isinstance(project_id, bytes):
        project_id = project_id.decode("utf-8")
    if isinstance(external_id, bytes):
        external_id = external_id.decode("utf-8")
    parent = f"projects/{project_id}"
    tenant = talent.Tenant(external_id=external_id)

    response = client.create_tenant(parent=parent, tenant=tenant)
    print("Created Tenant")
    print(f"Name: {response.name}")
    print(f"External ID: {response.external_id}")
    return response.name

擷取用戶群

Java

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Java API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.talent.v4.GetTenantRequest;
import com.google.cloud.talent.v4.Tenant;
import com.google.cloud.talent.v4.TenantName;
import com.google.cloud.talent.v4.TenantServiceClient;
import java.io.IOException;

public class JobSearchGetTenant {

  public static void getTenant() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    getTenant(projectId, tenantId);
  }

  // Get Tenant by name.
  public static void getTenant(String projectId, String tenantId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      TenantName name = TenantName.of(projectId, tenantId);

      GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build();

      Tenant response = tenantServiceClient.getTenant(request);
      System.out.format("Name: %s%n", response.getName());
      System.out.format("External ID: %s%n", response.getExternalId());
    }
  }
}

Python

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Python API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


from google.cloud import talent


def get_tenant(project_id, tenant_id):
    """Get Tenant by name"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID'

    if isinstance(project_id, bytes):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, bytes):
        tenant_id = tenant_id.decode("utf-8")
    name = client.tenant_path(project_id, tenant_id)

    response = client.get_tenant(name=name)
    print(f"Name: {response.name}")
    print(f"External ID: {response.external_id}")

列出用戶群

Java

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Java API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.talent.v4.ListTenantsRequest;
import com.google.cloud.talent.v4.ProjectName;
import com.google.cloud.talent.v4.Tenant;
import com.google.cloud.talent.v4.TenantServiceClient;
import java.io.IOException;

public class JobSearchListTenants {

  public static void listTenants() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    listTenants(projectId);
  }

  // List Tenants.
  public static void listTenants(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      ProjectName parent = ProjectName.of(projectId);

      ListTenantsRequest request =
          ListTenantsRequest.newBuilder().setParent(parent.toString()).build();

      for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
        System.out.format("Tenant Name: %s%n", responseItem.getName());
        System.out.format("External ID: %s%n", responseItem.getExternalId());
      }
    }
  }
}

Python

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Python API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


from google.cloud import talent


def list_tenants(project_id):
    """List Tenants"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'

    if isinstance(project_id, bytes):
        project_id = project_id.decode("utf-8")
    parent = f"projects/{project_id}"

    # Iterate over all results
    for response_item in client.list_tenants(parent=parent):
        print(f"Tenant Name: {response_item.name}")
        print(f"External ID: {response_item.external_id}")

刪除用戶群

Java

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Java API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.talent.v4.DeleteTenantRequest;
import com.google.cloud.talent.v4.TenantName;
import com.google.cloud.talent.v4.TenantServiceClient;
import java.io.IOException;

public class JobSearchDeleteTenant {

  public static void deleteTenant() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    deleteTenant(projectId, tenantId);
  }

  // Delete Tenant.
  public static void deleteTenant(String projectId, String tenantId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      TenantName name = TenantName.of(projectId, tenantId);

      DeleteTenantRequest request =
          DeleteTenantRequest.newBuilder().setName(name.toString()).build();

      tenantServiceClient.deleteTenant(request);
      System.out.println("Deleted Tenant.");
    }
  }
}

Python

如要瞭解如何安裝及使用 CTS 的用戶端程式庫,請參閱 CTS 用戶端程式庫。 詳情請參閱 CTS Python API 參考說明文件

如要向 CTS 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


from google.cloud import talent


def delete_tenant(project_id, tenant_id):
    """Delete Tenant"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID)'

    if isinstance(project_id, bytes):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, bytes):
        tenant_id = tenant_id.decode("utf-8")
    name = client.tenant_path(project_id, tenant_id)

    client.delete_tenant(name=name)
    print("Deleted Tenant.")