创建和更新公司

Cloud Talent Solution 中的公司资源代表一家公司。属于该公司的任何招聘信息均简称为招聘信息帖子,是针对该公司内的一个空缺职位而创建的。其中包含公司名称和地址等信息,以及将 Cloud Talent Solution 服务内的资源与您的内部数据库相关联的内部字段。

创建公司

要创建公司,请向 companies 端点发送 POST 请求,并至少指定两个必填字段。如需详细了解如何创建公司,请参阅“快速入门:创建公司和职位”页面。此外,还有视频教程和交互式 Codelab 可供使用

Go

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
)

// 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: %v", err)
	}

	// 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: %v", err)
	}

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

	return resp, nil
}

Java

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


import com.google.cloud.talent.v4beta1.Company;
import com.google.cloud.talent.v4beta1.CompanyServiceClient;
import com.google.cloud.talent.v4beta1.CreateCompanyRequest;
import com.google.cloud.talent.v4beta1.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 {
    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.printf("Name: %s\n", response.getName());
      System.out.printf("Display Name: %s\n", response.getDisplayName());
      System.out.printf("External ID: %s\n", response.getExternalId());
    }
  }
}

PHP

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\CompanyServiceClient;
use Google\Cloud\Talent\V4beta1\Company;

/**
 * Create Company.
 *
 * @param string $projectId Your Google Cloud Project ID
 * @param string $tenantId  Identifier of the Tenant
 */
function sampleCreateCompany($projectId, $tenantId, $displayName, $externalId)
{

    $companyServiceClient = new CompanyServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    // $displayName = 'My Company Name';
    // $externalId = 'Identifier of this company in my system';
    $formattedParent = $companyServiceClient->tenantName($projectId, $tenantId);
    $company = new Company();
    $company->setDisplayName($displayName);
    $company->setExternalId($externalId);

    try {
        $response = $companyServiceClient->createCompany($formattedParent, $company);
        printf('Created Company'.PHP_EOL);
        printf('Name: %s'.PHP_EOL, $response->getName());
        printf('Display Name: %s'.PHP_EOL, $response->getDisplayName());
        printf('External ID: %s'.PHP_EOL, $response->getExternalId());
    } finally {
        $companyServiceClient->close();
    }

}

Ruby

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


# Create Company
#
# @param project_id {String} Your Google Cloud Project ID
# @param tenant_id {String} Identifier of the Tenant
def sample_create_company project_id, tenant_id, display_name, external_id
  # Instantiate a client
  company_client = Google::Cloud::Talent::CompanyService.new version: :v4beta1

  # 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"
  formatted_parent = company_client.class.tenant_path(project_id, tenant_id)
  company = { display_name: display_name, external_id: external_id }

  response = company_client.create_company(formatted_parent, company)
  puts "Created Company"
  puts "Name: #{response.name}"
  puts "Display Name: #{response.display_name}"
  puts "External ID: #{response.external_id}"
end

C#

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

public static object CreateCompany(string projectId, string tenantId, string displayName, string externalId)
{
    CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
    TenantName tenantName = TenantName.FromProjectTenant(projectId, tenantId);

    Company company = new Company
    {
        DisplayName = displayName,
        ExternalId = externalId
    };

    CreateCompanyRequest request = new CreateCompanyRequest
    {
        ParentAsTenantName = tenantName,
        Company = company
    };

    Company response = companyServiceClient.CreateCompany(request);

    Console.WriteLine("Created Company");
    Console.WriteLine($"Name: {response.Name}");
    Console.WriteLine($"Display Name: {response.DisplayName}");
    Console.WriteLine($"External ID: {response.ExternalId}");
    return 0;
}

必填字段

创建/更新请求中必须包含以下字段:

  • displayName:与职位一起显示的雇主名称,例如“ Google LLC”。

  • externalId:您用于该公司的内部 ID。此字段允许您将内部标识符映射到 Google 系统中的对应公司。如果公司没有单独的内部标识符,请将此字段设置为与 displayName 相同的值。

常用字段

  • headquartersAddress:公司总部的街道地址,可能与工作地点不同。Cloud Talent Solution 仅允许每家公司有一个公司总部地址。该服务会尝试对地址进行地理定位,并在 derivedInfo.headquartersLocation(仅为输出)中填充更具体的地点。

  • size:存储分区值,根据员工人数来表示公司规模(从 MINIGIANT)。请参阅枚举的 size 参考信息及其定义。

  • eeoText:一个字符串,包含与该公司的所有职位关联的公平就业机会法律免责声明文本。

  • keywordSearchableJobCustomAttributes:指定该公司上的 customAttributes 应该编入索引,并且可通过常规关键字搜索进行搜索。

保密型公司

如果您要发布保密型职位,我们建议您创建一个模仿公司字段的单独公司,但要对 displayNameexternalId 和任何其他可识别出公司的字段进行混淆处理。

如果最终雇主应该匿名(例如“劳务中介”用例),建议将 externalIddisplayName 设置为随机但唯一的值。

检索公司

Go

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
)

// 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: %v", err)
	}

	// 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: %v", err)
	}

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

	return resp, nil
}

Java

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


import com.google.cloud.talent.v4beta1.Company;
import com.google.cloud.talent.v4beta1.CompanyName;
import com.google.cloud.talent.v4beta1.CompanyServiceClient;
import com.google.cloud.talent.v4beta1.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 {
    try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
      CompanyName name = CompanyName.ofProjectTenantCompanyName(projectId, tenantId, companyId);

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

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

PHP

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\CompanyServiceClient;

/** Get Company */
function sampleGetCompany($projectId, $tenantId, $companyId)
{

    $companyServiceClient = new CompanyServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    // $companyId = 'Company ID';
    $formattedName = $companyServiceClient->companyName($projectId, $tenantId, $companyId);

    try {
        $response = $companyServiceClient->getCompany($formattedName);
        printf('Company name: %s'.PHP_EOL, $response->getName());
        printf('Display name: %s'.PHP_EOL, $response->getDisplayName());
    } finally {
        $companyServiceClient->close();
    }

}

Ruby

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


# Get Company
def sample_get_company project_id, tenant_id, company_id
  # Instantiate a client
  company_client = Google::Cloud::Talent::CompanyService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID (using tenancy is optional)"
  # company_id = "Company ID"
  formatted_name = company_client.class.company_path(project_id, tenant_id, company_id)

  response = company_client.get_company(formatted_name)
  puts "Company name: #{response.name}"
  puts "Display name: #{response.display_name}"
end

C#

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

public static object GetCompany(string projectId, string tenantId, string companyId)
{
    CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
    CompanyName companyName = CompanyName.FromProjectTenantCompany(projectId, tenantId, companyId);

    GetCompanyRequest request = new GetCompanyRequest
    {
        CompanyName = companyName
    };
    var response = companyServiceClient.GetCompany(request);
    Console.WriteLine($"Company name: {response.Name}");
    Console.WriteLine($"Display name: {response.DisplayName}");
    return 0;
}

列出公司

Go

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

import (
	"context"
	"fmt"
	"io"

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

// 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: %v", err)
	}

	// 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: %v", 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

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


import com.google.cloud.talent.v4beta1.Company;
import com.google.cloud.talent.v4beta1.CompanyServiceClient;
import com.google.cloud.talent.v4beta1.ListCompaniesRequest;
import com.google.cloud.talent.v4beta1.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 {
    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.printf("Company Name: %s\n", responseItem.getName());
        System.out.printf("Display Name: %s\n", responseItem.getDisplayName());
        System.out.printf("External ID: %s\n", responseItem.getExternalId());
      }
    }
  }
}

PHP

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\CompanyServiceClient;

/**
 * List Companies.
 *
 * @param string $projectId Your Google Cloud Project ID
 * @param string $tenantId  Identifier of the Tenant
 */
function sampleListCompanies($projectId, $tenantId)
{

    $companyServiceClient = new CompanyServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    $formattedParent = $companyServiceClient->tenantName($projectId, $tenantId);

    try {
        // Iterate through all elements
        $pagedResponse = $companyServiceClient->listCompanies($formattedParent);
        foreach ($pagedResponse->iterateAllElements() as $responseItem) {
            printf('Company Name: %s'.PHP_EOL, $responseItem->getName());
            printf('Display Name: %s'.PHP_EOL, $responseItem->getDisplayName());
            printf('External ID: %s'.PHP_EOL, $responseItem->getExternalId());
        }
    } finally {
        $companyServiceClient->close();
    }

}

Ruby

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


# List Companies
#
# @param project_id {String} Your Google Cloud Project ID
# @param tenant_id {String} Identifier of the Tenant
def sample_list_companies project_id, tenant_id
  # Instantiate a client
  company_client = Google::Cloud::Talent::CompanyService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID (using tenancy is optional)"
  formatted_parent = company_client.class.tenant_path(project_id, tenant_id)

  # Iterate over all results.
  company_client.list_companies(formatted_parent).each do |element|
    puts "Company Name: #{element.name}"
    puts "Display Name: #{element.display_name}"
    puts "External ID: #{element.external_id}"
  end
end

C#

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

public static object ListCompanies(string projectId, string tenantId)
{
    CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
    TenantName tenantName = TenantName.FromProjectTenant(projectId, tenantId);

    ListCompaniesRequest request = new ListCompaniesRequest
    {
        ParentAsTenantName = tenantName
    };
    var companies = companyServiceClient.ListCompanies(request);
    foreach (var company in companies)
    {
        Console.WriteLine($"Company Name: {company.Name}");
        Console.WriteLine($"Display Name: {company.DisplayName}");
        Console.WriteLine($"External ID: {company.ExternalId}");
    }
    return 0;
}

删除公司

Go

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
)

// 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: %v", err)
	}

	// 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): %v", companyName, err)
	}

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

	return nil
}

// [END job_search_delete_company

Java

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


import com.google.cloud.talent.v4beta1.CompanyName;
import com.google.cloud.talent.v4beta1.CompanyServiceClient;
import com.google.cloud.talent.v4beta1.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 {
    try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
      CompanyName name = CompanyName.ofProjectTenantCompanyName(projectId, tenantId, companyId);

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

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

PHP

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\CompanyServiceClient;

/** Delete Company */
function sampleDeleteCompany($projectId, $tenantId, $companyId)
{

    $companyServiceClient = new CompanyServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID (using tenancy is optional)';
    // $companyId = 'ID of the company to delete';
    $formattedName = $companyServiceClient->companyName($projectId, $tenantId, $companyId);

    try {
        $companyServiceClient->deleteCompany($formattedName);
        printf('Deleted company'.PHP_EOL);
    } finally {
        $companyServiceClient->close();
    }

}

Ruby

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库


# Delete Company
def sample_delete_company project_id, tenant_id, company_id
  # Instantiate a client
  company_client = Google::Cloud::Talent::CompanyService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID (using tenancy is optional)"
  # company_id = "ID of the company to delete"
  formatted_name = company_client.class.company_path(project_id, tenant_id, company_id)

  company_client.delete_company(formatted_name)

  puts "Deleted company"
end

C#

如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库

public static object DeleteCompany(string projectId, string tenantId, string companyId)
{
    CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
    CompanyName companyName = CompanyName.FromProjectTenantCompany(projectId, tenantId, companyId);
    DeleteCompanyRequest request = new DeleteCompanyRequest
    {
        CompanyName = companyName
    };

    companyServiceClient.DeleteCompany(request);

    Console.WriteLine("Deleted Company.");
    return 0;
}