建立及更新公司

Cloud Talent Solution 中的一個「公司」資源代表一家公司。而任何屬於這家公司的工作,就是指針對這家公司的職缺所建立的工作張貼項目。工作張貼項目包含公司名稱和地址等資訊,以及可將 Cloud Talent Solution 服務中的資源連回您內部資料庫的內部欄位。

建立公司

如要建立公司,請將 POST 要求傳送至 companies 端點,而且至少要指定兩個必填欄位。想進一步瞭解如何建立公司,請參閱快速入門:建立公司和工作頁面。此外,我們也提供影片教學課程和互動式程式碼研究室。

下列範例說明如何建立新用戶端來執行要求。建議您為每個程式或系統程序建立一個用戶端,然後使用連線共用或單例用戶端,在多個要求之間共用該用戶端。為每個要求建立新用戶端可能會導致效能問題,或觸發 DoS 保護機制。

Go

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

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

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"cloud.google.com/go/talent/apiv4beta1/talentpb"
)

// createCompany creates a company as given.
func createCompany(w io.Writer, projectID, externalID, displayName string) (*talentpb.Company, error) {
	ctx := context.Background()

	// Initializes a companyService client.
	c, err := talent.NewCompanyClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("talent.NewCompanyClient: %w", err)
	}
	defer c.Close()

	// Construct a createCompany request.
	req := &talentpb.CreateCompanyRequest{
		Parent: fmt.Sprintf("projects/%s", projectID),
		Company: &talentpb.Company{
			ExternalId:  externalID,
			DisplayName: displayName,
		},
	}

	resp, err := c.CreateCompany(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("CreateCompany: %w", err)
	}

	fmt.Fprintf(w, "Created company: %q\n", resp.GetName())

	return resp, nil
}

Java

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

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


import com.google.cloud.talent.v4.Company;
import com.google.cloud.talent.v4.CompanyServiceClient;
import com.google.cloud.talent.v4.CreateCompanyRequest;
import com.google.cloud.talent.v4.TenantName;
import java.io.IOException;

public class JobSearchCreateCompany {

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

  // Create a company.
  public static void createCompany(
      String projectId, String tenantId, String displayName, 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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);
      Company company =
          Company.newBuilder().setDisplayName(displayName).setExternalId(externalId).build();

      CreateCompanyRequest request =
          CreateCompanyRequest.newBuilder()
              .setParent(parent.toString())
              .setCompany(company)
              .build();

      Company response = companyServiceClient.createCompany(request);
      System.out.println("Created Company");
      System.out.format("Name: %s%n", response.getName());
      System.out.format("Display Name: %s%n", response.getDisplayName());
      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 Company
 *
 * @param projectId {string} Your Google Cloud Project ID
 * @param tenantId {string} Identifier of the Tenant
 */
function sampleCreateCompany(projectId, tenantId, displayName, externalId) {
  const client = new talent.CompanyServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const displayName = 'My Company Name';
  // const externalId = 'Identifier of this company in my system';
  const formattedParent = client.tenantPath(projectId, tenantId);
  const company = {
    displayName: displayName,
    externalId: externalId,
  };
  const request = {
    parent: formattedParent,
    company: company,
  };
  client
    .createCompany(request)
    .then(responses => {
      const response = responses[0];
      console.log('Created Company');
      console.log(`Name: ${response.name}`);
      console.log(`Display Name: ${response.displayName}`);
      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_company(project_id, tenant_id, display_name, external_id):
    """Create Company"""

    client = talent.CompanyServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # display_name = 'My Company Name'
    # external_id = 'Identifier of this company in my system'

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

    response = client.create_company(parent=parent, company=company)
    print("Created Company")
    print(f"Name: {response.name}")
    print(f"Display Name: {response.display_name}")
    print(f"External ID: {response.external_id}")
    return response.name

必填欄位

以下是建立/更新要求中的必填欄位:

  • displayName:與職缺一同顯示的雇主名稱,例如「Google LLC」。

  • externalId:這家公司的內部 ID。這個欄位可讓您將內部 ID 對應到 Google 系統中的公司。如果公司沒有個別的內部 ID,請將這個欄位設定成與 displayName 相同的值。

常用欄位

  • headquartersAddress:公司總部的街道地址,可能與工作地點不同。針對每家公司,Cloud Talent Solution 只接受一個總部地址。服務會嘗試取得該地址的地理位置,並盡可能在 derivedInfo.headquartersLocation (僅限輸出) 中填入更具體的地點。

  • size:代表公司規模 (以員工人數判斷) 的值區值 (從 MINIGIANT)。如需列舉和定義,請參閱 size 參考資料。

  • eeoText:一個字串,包含與這家公司所有職缺相關聯的公平就業機會法律免責事項文字。

  • keywordSearchableJobCustomAttributes:指定系統應該為這家公司所提供工作的哪些 customAttributes 建立索引,供使用者以一般關鍵字進行搜尋。

要保密的公司

如果您想張貼要保密的工作,我們建議您建立個別的公司,並模仿原本公司的欄位,但是將 displayNameexternalId 和所有其他可辨識公司的欄位進行模糊處理。

如果雇主的身分必須保密 (例如人力仲介機構),建議您將 externalIddisplayName 設為不重複的隨機值。

擷取公司

Go

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

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

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"cloud.google.com/go/talent/apiv4beta1/talentpb"
)

// getCompany gets an existing company by its resource name.
func getCompany(w io.Writer, projectID, companyID string) (*talentpb.Company, error) {
	ctx := context.Background()

	// Initialize a companyService client.
	c, err := talent.NewCompanyClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("talent.NewCompanyClient: %w", err)
	}
	defer c.Close()

	// Construct a getCompany request.
	companyName := fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)
	req := &talentpb.GetCompanyRequest{
		// The resource name of the company to be retrieved.
		// The format is "projects/{project_id}/companies/{company_id}".
		Name: companyName,
	}

	resp, err := c.GetCompany(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("GetCompany: %w", err)
	}

	fmt.Fprintf(w, "Company: %q\n", resp.GetName())
	fmt.Fprintf(w, "Company display name: %q\n", resp.GetDisplayName())

	return resp, nil
}

Java

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

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


import com.google.cloud.talent.v4.Company;
import com.google.cloud.talent.v4.CompanyName;
import com.google.cloud.talent.v4.CompanyServiceClient;
import com.google.cloud.talent.v4.GetCompanyRequest;
import java.io.IOException;

public class JobSearchGetCompany {

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

  // Get Company.
  public static void getCompany(String projectId, String tenantId, String companyId)
      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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
      CompanyName name = CompanyName.of(projectId, tenantId, companyId);

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

      Company response = companyServiceClient.getCompany(request);
      System.out.format("Company name: %s%n", response.getName());
      System.out.format("Display name: %s%n", response.getDisplayName());
    }
  }
}

Node.js

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

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


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

/** Get Company */
function sampleGetCompany(projectId, tenantId, companyId) {
  const client = new talent.CompanyServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const companyId = 'Company ID';
  const formattedName = client.companyPath(projectId, tenantId, companyId);
  client
    .getCompany({name: formattedName})
    .then(responses => {
      const response = responses[0];
      console.log(`Company name: ${response.name}`);
      console.log(`Display name: ${response.displayName}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

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

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


from google.cloud import talent


def get_company(project_id, tenant_id, company_id):
    """Get Company"""

    client = talent.CompanyServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # company_id = 'Company 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")
    if isinstance(company_id, bytes):
        company_id = company_id.decode("utf-8")
    name = client.company_path(project_id, tenant_id, company_id)

    response = client.get_company(name=name)
    print(f"Company name: {response.name}")
    print(f"Display name: {response.display_name}")

列出公司

Go

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

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

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"cloud.google.com/go/talent/apiv4beta1/talentpb"
	"google.golang.org/api/iterator"
)

// listCompanies lists all companies in the project.
func listCompanies(w io.Writer, projectID string) error {
	ctx := context.Background()

	// Initialize a compnayService client.
	c, err := talent.NewCompanyClient(ctx)
	if err != nil {
		return fmt.Errorf("talent.NewCompanyClient: %w", err)
	}
	defer c.Close()

	// Construct a listCompanies request.
	req := &talentpb.ListCompaniesRequest{
		Parent: "projects/" + projectID,
	}

	it := c.ListCompanies(ctx, req)

	for {
		resp, err := it.Next()
		if err == iterator.Done {
			return nil
		}
		if err != nil {
			return fmt.Errorf("it.Next: %w", err)
		}
		fmt.Fprintf(w, "Listing company: %q\n", resp.GetName())
		fmt.Fprintf(w, "Display name: %v\n", resp.GetDisplayName())
		fmt.Fprintf(w, "External ID: %v\n", resp.GetExternalId())
	}
}

Java

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

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


import com.google.cloud.talent.v4.Company;
import com.google.cloud.talent.v4.CompanyServiceClient;
import com.google.cloud.talent.v4.ListCompaniesRequest;
import com.google.cloud.talent.v4.TenantName;
import java.io.IOException;

public class JobSearchListCompanies {

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

  // List Companies.
  public static void listCompanies(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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
      TenantName parent = TenantName.of(projectId, tenantId);

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

      for (Company responseItem : companyServiceClient.listCompanies(request).iterateAll()) {
        System.out.format("Company Name: %s%n", responseItem.getName());
        System.out.format("Display Name: %s%n", responseItem.getDisplayName());
        System.out.format("External ID: %s%n", responseItem.getExternalId());
      }
    }
  }
}

Node.js

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

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


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

/**
 * List Companies
 *
 * @param projectId {string} Your Google Cloud Project ID
 * @param tenantId {string} Identifier of the Tenant
 */
function sampleListCompanies(projectId, tenantId) {
  const client = new talent.CompanyServiceClient();
  // Iterate over all elements.
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  const formattedParent = client.tenantPath(projectId, tenantId);

  client
    .listCompanies({parent: formattedParent})
    .then(responses => {
      const resources = responses[0];
      for (const resource of resources) {
        console.log(`Company Name: ${resource.name}`);
        console.log(`Display Name: ${resource.displayName}`);
        console.log(`External ID: ${resource.externalId}`);
      }
    })
    .catch(err => {
      console.error(err);
    });
}

Python

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

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


from google.cloud import talent


def list_companies(project_id, tenant_id):
    """List Companies"""

    client = talent.CompanyServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'

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

    # Iterate over all results
    results = []
    for company in client.list_companies(parent=parent):
        results.append(company.name)
        print(f"Company Name: {company.name}")
        print(f"Display Name: {company.display_name}")
        print(f"External ID: {company.external_id}")
    return results

刪除公司

Go

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

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

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"cloud.google.com/go/talent/apiv4beta1/talentpb"
)

// deleteCompany deletes an existing company. Companies with
// existing jobs cannot be deleted until those jobs have been deleted.
func deleteCompany(w io.Writer, projectID, companyID string) error {
	ctx := context.Background()

	// Initialize a companyService client.
	c, err := talent.NewCompanyClient(ctx)
	if err != nil {
		return fmt.Errorf("talent.NewCompanyClient: %w", err)
	}
	defer c.Close()

	// Construct a deleteCompany request.
	companyName := fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)
	req := &talentpb.DeleteCompanyRequest{
		// The resource name of the company to be deleted.
		// The format is "projects/{project_id}/companies/{company_id}".
		Name: companyName,
	}

	if err := c.DeleteCompany(ctx, req); err != nil {
		return fmt.Errorf("DeleteCompany(%s): %w", companyName, err)
	}

	fmt.Fprintf(w, "Deleted company: %q\n", companyName)

	return nil
}

Java

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

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


import com.google.cloud.talent.v4.CompanyName;
import com.google.cloud.talent.v4.CompanyServiceClient;
import com.google.cloud.talent.v4.DeleteCompanyRequest;
import java.io.IOException;

public class JobSearchDeleteCompany {

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

  // Delete Company.
  public static void deleteCompany(String projectId, String tenantId, String companyId)
      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 (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
      CompanyName name = CompanyName.of(projectId, tenantId, companyId);

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

      companyServiceClient.deleteCompany(request);
      System.out.println("Deleted company");
    }
  }
}

Node.js

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

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


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

/** Delete Company */
function sampleDeleteCompany(projectId, tenantId, companyId) {
  const client = new talent.CompanyServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const companyId = 'ID of the company to delete';
  const formattedName = client.companyPath(projectId, tenantId, companyId);
  client.deleteCompany({name: formattedName}).catch(err => {
    console.error(err);
  });
  console.log('Deleted company');
}

Python

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

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


from google.cloud import talent


def delete_company(project_id, tenant_id, company_id):
    """Delete Company"""

    client = talent.CompanyServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # company_id = 'ID of the company to delete'

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

    client.delete_company(name=name)
    print("Deleted company")