使用客户端创建公司。
包含此代码示例的文档页面
如需查看上下文中使用的代码示例,请参阅以下文档:
代码示例
C#
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;
}
Java
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 {
// 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());
}
}
}