Mendapatkan lowongan dengan klien (v4beta1)

Mendapatkan tugas dengan klien.

Jelajahi lebih lanjut

Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:

Contoh kode

Go

Untuk mempelajari cara menginstal dan menggunakan library klien untuk CTS, lihat library klien CTS. Untuk informasi selengkapnya, lihat dokumentasi referensi API CTS Go.

Untuk mengautentikasi ke CTS, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"fmt"
	"io"

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

// 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: %w", err)
	}
	defer c.Close()

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

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

	return resp, err
}

Node.js

Untuk mempelajari cara menginstal dan menggunakan library klien untuk CTS, lihat library klien CTS. Untuk informasi selengkapnya, lihat dokumentasi referensi API CTS Node.js.

Untuk mengautentikasi ke CTS, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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

Untuk mempelajari cara menginstal dan menggunakan library klien untuk CTS, lihat library klien CTS. Untuk informasi selengkapnya, lihat dokumentasi referensi API CTS Python.

Untuk mengautentikasi ke CTS, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


from google.cloud import talent

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, bytes):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, bytes):
        tenant_id = tenant_id.decode("utf-8")
    if isinstance(job_id, bytes):
        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}")

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud.