クライアントを使用して会社を一覧表示します。
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
Go
import (
"context"
"fmt"
"io"
talent "cloud.google.com/go/talent/apiv4beta1"
"cloud.google.com/go/talent/apiv4beta1/talentpb"
"google.golang.org/api/iterator"
)
// 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)
}
defer c.Close()
// 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())
}
}
Node.js
const talent = require('@google-cloud/talent').v4;
/**
* List Companies
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the Tenant
*/
function sampleListCompanies(projectId, tenantId) {
const client = new talent.CompanyServiceClient();
// Iterate over all elements.
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
const formattedParent = client.tenantPath(projectId, tenantId);
client
.listCompanies({parent: formattedParent})
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
console.log(`Company Name: ${resource.name}`);
console.log(`Display Name: ${resource.displayName}`);
console.log(`External ID: ${resource.externalId}`);
}
})
.catch(err => {
console.error(err);
});
}
Python
from google.cloud import talent
import six
def list_companies(project_id, tenant_id):
"""List Companies"""
client = talent.CompanyServiceClient()
# project_id = 'Your Google Cloud Project ID'
# tenant_id = 'Your Tenant ID (using tenancy is optional)'
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")
parent = f"projects/{project_id}/tenants/{tenant_id}"
# Iterate over all results
results = []
for company in client.list_companies(parent=parent):
results.append(company.name)
print(f"Company Name: {company.name}")
print(f"Display Name: {company.display_name}")
print(f"External ID: {company.external_id}")
return results
次のステップ
他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。