创建和更新公司 (v3)

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

创建公司

要创建公司,请向 companies 端点发送 POST 请求,并至少指定两个必填字段。如需详细了解如何创建公司,请参阅“快速入门:创建公司和职位”页面。

Java

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


/**
 * Create a company.
 */
public static Company createCompany(Company companyToBeCreated) throws IOException {
  try {
    CreateCompanyRequest createCompanyRequest =
        new CreateCompanyRequest().setCompany(companyToBeCreated);
    Company companyCreated =
        talentSolutionClient.projects()
            .companies()
            .create(DEFAULT_PROJECT_ID, createCompanyRequest)
            .execute();
    System.out.println("Company created: " + companyCreated);
    return companyCreated;
  } catch (IOException e) {
    System.out.println("Got exception while creating company");
    throw e;
  }
}

Python

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

def create_company(client_service, company_to_be_created):
    try:
        request = {'company': company_to_be_created}
        company_created = client_service.projects().companies().create(
            parent=parent, body=request).execute()
        print('Company created: %s' % company_created)
        return company_created
    except Error as e:
        print('Got exception while creating company')
        raise e

C#

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


public static Company CreateCompany(Company companyToBeCreated)
{
    try
    {
        CreateCompanyRequest createCompanyRequest = new CreateCompanyRequest();
        createCompanyRequest.Company = companyToBeCreated;
        Company companyCreated = jobServiceClient.Projects.Companies.Create(createCompanyRequest, parent).Execute();
        Console.WriteLine("Created company: " + ToJsonString(companyCreated));
        return companyCreated;
    }
    catch (Exception e)
    {
        Console.WriteLine("Got exception while creating company");
        throw e;
    }
}

Go

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


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

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	parent := "projects/" + projectID
	req := &talent.CreateCompanyRequest{
		Company: companyToCreate,
	}
	company, err := service.Projects.Companies.Create(parent, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to create company %q: %v", companyToCreate.DisplayName, err)
	}

	return company, nil
}

Node.js

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


/**
 * Create a company.
 */
const createCompany = async (jobServiceClient, companyToBeCreated) => {
  try {
    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        company: companyToBeCreated,
      },
    };

    const companyCreated = await jobServiceClient.projects.companies.create(
      request
    );

    console.log(`Company created: ${JSON.stringify(companyCreated.data)}`);
    return companyCreated.data;
  } catch (e) {
    console.error(`Failed to create company! ${e}`);
    throw e;
  }
};

Ruby

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

# project_id              = "Id of the project"
# company_to_be_created   = "Company to be created"

require "google/apis/jobs_v3"

jobs = Google::Apis::JobsV3
talent_solution_client = jobs::CloudTalentSolutionService.new
# @see
# https://developers.google.com/identity/protocols/application-default-credentials#callingruby
talent_solution_client.authorization = Google::Auth.get_application_default(
  "https://www.googleapis.com/auth/jobs"
)

begin
  create_company_request = jobs::CreateCompanyRequest.new company: company_to_be_created
  company_created = talent_solution_client.create_company project_id, create_company_request
  puts "Company created: #{company_created.to_json}"
  return company_created
rescue StandardError => e
  puts "Exception occurred while creating company: #{e}"
end

必填字段

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

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

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

常用字段

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

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

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

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

更新公司

要更新公司,请向以下端点发送 PATCH 请求:

 PATCH https://jobs.googleapis.com/v3/COMPANY_NAME 

其中 COMPANY_NAME 是公司的 name 字段的值。name 是公司的唯一标识符,是在创建时以及通过 company.getlist 请求返回的。

请求正文必须包含完整的资源,包括未更新的字段。可以在 updateMask 中设置这些字段。如果在 updateMask 中设置了字段,则系统仅会更新这些字段,忽略对其他字段的更新。如果未设置 updateMask,则系统会更新所有字段。

Java

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


/**
 * Updates a company.
 */
public static Company updateCompany(String companyName, Company companyToBeUpdated)
    throws IOException {
  try {
    UpdateCompanyRequest updateCompanyRequest =
        new UpdateCompanyRequest().setCompany(companyToBeUpdated);

    Company companyUpdated =
        talentSolutionClient
            .projects()
            .companies()
            .patch(companyName, updateCompanyRequest)
            .execute();

    System.out.println("Company updated: " + companyUpdated);
    return companyUpdated;
  } catch (IOException e) {
    System.out.println("Got exception while updating company");
    throw e;
  }
}

Python

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

def update_company(client_service, company_name, company_to_be_updated):
    try:
        request = {'company': company_to_be_updated}
        company_updated = client_service.projects().companies().patch(
            name=company_name, body=request).execute()
        print('Company updated: %s' % company_updated)
        return company_updated
    except Error as e:
        print('Got exception while updating company')
        raise e

C#

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


public static Company UpdateCompany(String companyName, Company companyToBeUpdated)
{
    try
    {
        UpdateCompanyRequest updateCompanyRequest = new UpdateCompanyRequest()
        {
            Company = companyToBeUpdated
        };
        Company companyUpdated = jobServiceClient.Projects.Companies.Patch(updateCompanyRequest, companyName).Execute();
        Console.WriteLine("Company updated: " + ToJsonString(companyUpdated));
        return companyUpdated;
    }
    catch (Exception e)
    {
        Console.WriteLine("Got exception while updating company");
        throw e;
    }
}

Go

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


// updateCompany update a company with all fields.
func updateCompany(w io.Writer, name string, companyToUpdate *talent.Company) (*talent.Company, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	updateCompanyRequest := &talent.UpdateCompanyRequest{
		Company: companyToUpdate,
	}
	company, err := service.Projects.Companies.Patch(name, updateCompanyRequest).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to update company %q: %v", name, err)
	}

	return company, nil
}

Node.js

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


/**
 * Updates a company.
 */
const updateCompany = async (
  jobServiceClient,
  companyName,
  companyToBeUpdated
) => {
  try {
    const request = {
      name: companyName,
      resource: {
        company: companyToBeUpdated,
      },
    };

    const companyUpdated = await jobServiceClient.projects.companies.patch(
      request
    );

    console.log(`Company updated: ${JSON.stringify(companyUpdated.data)}`);
    return companyUpdated.data;
  } catch (e) {
    console.error(`Got exception while updating company! ${e}`);
    throw e;
  }
};

Ruby

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

# company_name     = "The name of the company you want to update. The format is "projects/{project_id}/companies/{company_id}""
# company_updated  = "The new company object to be updated"

require "google/apis/jobs_v3"

jobs = Google::Apis::JobsV3
talent_solution_client = jobs::CloudTalentSolutionService.new
# @see
# https://developers.google.com/identity/protocols/application-default-credentials#callingruby
talent_solution_client.authorization = Google::Auth.get_application_default(
  "https://www.googleapis.com/auth/jobs"
)

begin
  update_company_request = jobs::UpdateCompanyRequest.new company: company_updated
  company_updated = talent_solution_client
                    .patch_project_company(company_name, update_company_request)
  puts "Company updated: #{company_updated.to_json}"
  return company_updated
rescue StandardError => e
  puts "Exception occurred while updating company: #{e}"
end

更新有 updateMask 的公司

Java

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


/**
 * Updates a company.
 */
public static Company updateCompanyWithFieldMask(String companyName, String fieldMask,
    Company companyToBeUpdated)
    throws IOException {
  try {
    // String foo = String.format("?updateCompanyFields=%s",fieldMask);
    UpdateCompanyRequest updateCompanyRequest =
        new UpdateCompanyRequest().setUpdateMask(fieldMask).setCompany(companyToBeUpdated);

    Company companyUpdated =
        talentSolutionClient
            .projects()
            .companies()
            .patch(companyName, updateCompanyRequest)
            .execute();

    System.out.println("Company updated: " + companyUpdated);
    return companyUpdated;
  } catch (IOException e) {
    System.out.println("Got exception while updating company");
    throw e;
  }
}

Python

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

def update_company_with_field_mask(client_service, company_name,
                                   company_to_be_updated, field_mask):
    try:
        request = {
            'company': company_to_be_updated,
            'update_mask': field_mask
        }
        company_updated = client_service.projects().companies().patch(
            name=company_name,
            body=request).execute()
        print('Company updated: %s' % company_updated)
        return company_updated
    except Error as e:
        print('Got exception while updating company with field mask')
        raise e

C#

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


public static Company UpdateCompanyWithFieldMask(string companyName, string fieldMask, Company companyToBeUpdated)
{
    try
    {
        UpdateCompanyRequest updateCompanyRequest = new UpdateCompanyRequest()
        {
            UpdateMask = fieldMask,
            Company = companyToBeUpdated
        };
        Company companyUpdated = jobServiceClient.Projects.Companies.Patch(updateCompanyRequest, companyName).Execute();
        Console.WriteLine("Company updated with updateMask: " + ToJsonString(companyUpdated));
        return companyUpdated;
    }
    catch (Exception e)
    {
        Console.WriteLine("Got exception while updating company with update mask");
        throw e;
    }
}

Go

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


// updateCompanyWithMask updates a company with specific fields.
// mask is a comma separated list of top-level fields of talent.Company.
func updateCompanyWithMask(w io.Writer, name string, mask string, companyToUpdate *talent.Company) (*talent.Company, error) {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, talent.CloudPlatformScope)
	if err != nil {
		return nil, fmt.Errorf("google.DefaultClient: %v", err)
	}
	// Create the jobs service client.
	service, err := talent.New(client)
	if err != nil {
		return nil, fmt.Errorf("talent.New: %v", err)
	}

	req := &talent.UpdateCompanyRequest{
		Company:    companyToUpdate,
		UpdateMask: mask,
	}
	company, err := service.Projects.Companies.Patch(name, req).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to update company %q with mask %q: %v", name, mask, err)
	}

	return company, nil
}

Node.js

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


/**
 * Updates a company with field mask.
 */
const updateCompanyWithFieldMask = async (
  jobServiceClient,
  companyName,
  companyToBeUpdated,
  fieldMask
) => {
  try {
    const request = {
      name: companyName,
      resource: {
        company: companyToBeUpdated,
        updateMask: fieldMask,
      },
    };

    const companyUpdated = await jobServiceClient.projects.companies.patch(
      request
    );

    console.log(`Company updated: ${JSON.stringify(companyUpdated.data)}`);
    return companyUpdated.data;
  } catch (e) {
    console.error(`Got exception while updating company with field mask! ${e}`);
    throw e;
  }
};

Ruby

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

# company_name     = "The name of the company you want to update. The format is "projects/{project_id}/companies/{company_id}""
# field_mask       = "The field mask you want to update"
# company_updated  = "The new company object to be updated"

require "google/apis/jobs_v3"

jobs = Google::Apis::JobsV3
talent_solution_client = jobs::CloudTalentSolutionService.new
# @see
# https://developers.google.com/identity/protocols/application-default-credentials#callingruby
talent_solution_client.authorization = Google::Auth.get_application_default(
  "https://www.googleapis.com/auth/jobs"
)

begin
  update_company_request = jobs::UpdateCompanyRequest.new company:     company_updated,
                                                          update_mask: field_mask
  company_updated = talent_solution_client
                    .patch_project_company(company_name, update_company_request)
  puts "Company updated with filedMask #{update_company_request.update_mask}. "
  puts "Updated company: #{company_updated.to_json}"
  return company_updated
rescue StandardError => e
  puts "Exception occurred while updating company with fieldMask: #{e}"
end

最佳做法

保密型公司

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

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