Diese Seite wurde von der Cloud Translation API übersetzt.
Switch to English

Job mit Client abrufen (v4beta1)

Job mit Client abrufen.

Dokumentationsseiten mit diesem Codebeispiel

Das Codebeispiel im Kontext finden Sie in der folgenden Dokumentation:

Codebeispiel

Go

import (
	"context"
	"fmt"
	"io"

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

// getJob gets an existing job by its resource name.
func getJob(w io.Writer, projectID, jobID string) (*talentpb.Job, error) {
	ctx := context.Background()

	// Initialize a jobService client.
	c, err := talent.NewJobClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("talent.NewJobClient: %v", err)
	}

	// Construct a getJob request.
	jobName := fmt.Sprintf("projects/%s/jobs/%s", projectID, jobID)
	req := &talentpb.GetJobRequest{
		// The resource name of the job to retrieve.
		// The format is "projects/{project_id}/jobs/{job_id}".
		Name: jobName,
	}

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

	fmt.Fprintf(w, "Job: %q\n", resp.GetName())
	fmt.Fprintf(w, "Job title: %v\n", resp.GetTitle())

	return resp, err
}

Java

/*
 * Please include the following imports to run this sample.
 *
 * import com.google.cloud.talent.v4beta1.GetJobRequest;
 * import com.google.cloud.talent.v4beta1.Job;
 * import com.google.cloud.talent.v4beta1.JobName;
 * import com.google.cloud.talent.v4beta1.JobServiceClient;
 * import com.google.cloud.talent.v4beta1.JobWithTenantName;
 */

public static void sampleGetJob() {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "Your Google Cloud Project ID";
  String tenantId = "Your Tenant ID (using tenancy is optional)";
  String jobId = "Job ID";
  sampleGetJob(projectId, tenantId, jobId);
}

/** Get Job */
public static void sampleGetJob(String projectId, String tenantId, String jobId) {
  try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
    JobName name = JobWithTenantName.of(projectId, tenantId, jobId);
    GetJobRequest request = GetJobRequest.newBuilder().setName(name.toString()).build();
    Job response = jobServiceClient.getJob(request);
    System.out.printf("Job name: %s\n", response.getName());
    System.out.printf("Requisition ID: %s\n", response.getRequisitionId());
    System.out.printf("Title: %s\n", response.getTitle());
    System.out.printf("Description: %s\n", response.getDescription());
    System.out.printf("Posting language: %s\n", response.getLanguageCode());
    for (String address : response.getAddressesList()) {
      System.out.printf("Address: %s\n", address);
    }
    for (String email : response.getApplicationInfo().getEmailsList()) {
      System.out.printf("Email: %s\n", email);
    }
    for (String websiteUri : response.getApplicationInfo().getUrisList()) {
      System.out.printf("Website: %s\n", websiteUri);
    }
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js


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

/** Get Job */
function sampleGetJob(projectId, tenantId, jobId) {
  const client = new talent.JobServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const jobId = 'Job ID';
  const formattedName = client.jobPath(projectId, tenantId, jobId);
  client
    .getJob({name: formattedName})
    .then(responses => {
      const response = responses[0];
      console.log(`Job name: ${response.name}`);
      console.log(`Requisition ID: ${response.requisitionId}`);
      console.log(`Title: ${response.title}`);
      console.log(`Description: ${response.description}`);
      console.log(`Posting language: ${response.languageCode}`);
      for (const address of response.addresses) {
        console.log(`Address: ${address}`);
      }
      for (const email of response.applicationInfo.emails) {
        console.log(`Email: ${email}`);
      }
      for (const websiteUri of response.applicationInfo.uris) {
        console.log(`Website: ${websiteUri}`);
      }
    })
    .catch(err => {
      console.error(err);
    });
}

Python


from google.cloud import talent
import six

def get_job(project_id, tenant_id, job_id):
    """Get Job"""

    client = talent.JobServiceClient()

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

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode("utf-8")
    if isinstance(job_id, six.binary_type):
        job_id = job_id.decode("utf-8")
    name = client.job_path(project_id, tenant_id, job_id)

    response = client.get_job(name=name)
    print(f"Job name: {response.name}")
    print(f"Requisition ID: {response.requisition_id}")
    print(f"Title: {response.title}")
    print(f"Description: {response.description}")
    print(f"Posting language: {response.language_code}")
    for address in response.addresses:
        print(f"Address: {address}")
    for email in response.application_info.emails:
        print(f"Email: {email}")
    for website_uri in response.application_info.uris:
        print(f"Website: {website_uri}")

Ruby

require "google/cloud/talent"

# Instantiate a client
job_service = Google::Cloud::Talent.job_service

# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is required)"
# job_id = "Job ID"
formatted_name = job_service.job_path project: project_id,
                                      tenant:  tenant_id,
                                      job:     job_id

response = job_service.get_job name: formatted_name
puts "Job name: #{response.name}"
puts "Requisition ID: #{response.requisition_id}"
puts "Title: #{response.title}"
puts "Description: #{response.description}"
puts "Posting language: #{response.language_code}"
response.addresses.each do |address|
  puts "Address: #{address}"
end
response.application_info.emails.each do |email|
  puts "Email: #{email}"
end
response.application_info.uris.each do |website_uri|
  puts "Website: #{website_uri}"
end