Répertoriez les locataires à l'aide du client.
Pages de documentation incluant cet exemple de code
Pour afficher l'exemple de code utilisé en contexte, consultez la documentation suivante :
Exemple de code
Java
/*
* Please include the following imports to run this sample.
*
* import com.google.cloud.talent.v4beta1.ListTenantsRequest;
* import com.google.cloud.talent.v4beta1.ProjectName;
* import com.google.cloud.talent.v4beta1.Tenant;
* import com.google.cloud.talent.v4beta1.TenantServiceClient;
*/
public static void sampleListTenants() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "Your Google Cloud Project ID";
sampleListTenants(projectId);
}
/** List Tenants */
public static void sampleListTenants(String projectId) {
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
ListTenantsRequest request =
ListTenantsRequest.newBuilder().setParent(parent.toString()).build();
for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
System.out.printf("Tenant Name: %s\n", responseItem.getName());
System.out.printf("External ID: %s\n", responseItem.getExternalId());
}
} catch (Exception exception) {
System.err.println("Failed to create the client due to: " + exception);
}
}
Node.js
const talent = require('@google-cloud/talent').v4;
/** List Tenants */
function sampleListTenants(projectId) {
const client = new talent.TenantServiceClient();
// Iterate over all elements.
// const projectId = 'Your Google Cloud Project ID';
const formattedParent = client.projectPath(projectId);
client
.listTenants({parent: formattedParent})
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
console.log(`Tenant Name: ${resource.name}`);
console.log(`External ID: ${resource.externalId}`);
}
})
.catch(err => {
console.error(err);
});
}
Python
from google.cloud import talent
import six
def list_tenants(project_id):
"""List Tenants"""
client = talent.TenantServiceClient()
# project_id = 'Your Google Cloud Project ID'
if isinstance(project_id, six.binary_type):
project_id = project_id.decode("utf-8")
parent = f"projects/{project_id}"
# Iterate over all results
for response_item in client.list_tenants(parent=parent):
print(f"Tenant Name: {response_item.name}")
print(f"External ID: {response_item.external_id}")
Ruby
require "google/cloud/talent"
# Instantiate a client
tenant_service = Google::Cloud::Talent.tenant_service
# project_id = "Your Google Cloud Project ID"
formatted_parent = tenant_service.project_path project: project_id
# Iterate over all results.
tenant_service.list_tenants(parent: formatted_parent).each do |element|
puts "Tenant Name: #{element.name}"
puts "External ID: #{element.external_id}"
end