获取租户 (v4beta1)

获取租户。

包含此代码示例的文档页面

如需查看上下文中使用的代码示例,请参阅以下文档:

代码示例

Java

/*
 * Please include the following imports to run this sample.
 *
 * import com.google.cloud.talent.v4beta1.GetTenantRequest;
 * import com.google.cloud.talent.v4beta1.Tenant;
 * import com.google.cloud.talent.v4beta1.TenantName;
 * import com.google.cloud.talent.v4beta1.TenantServiceClient;
 */

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

/** Get Tenant by name */
public static void sampleGetTenant(String projectId, String tenantId) {
  try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
    TenantName name = TenantName.of(projectId, tenantId);
    GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build();
    Tenant response = tenantServiceClient.getTenant(request);
    System.out.printf("Name: %s\n", response.getName());
    System.out.printf("External ID: %s\n", response.getExternalId());
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js


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

/** Get Tenant by name */
function sampleGetTenant(projectId, tenantId) {
  const client = new talent.TenantServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID';
  const formattedName = client.tenantPath(projectId, tenantId);
  client
    .getTenant({name: formattedName})
    .then(responses => {
      const response = responses[0];
      console.log(`Name: ${response.name}`);
      console.log(`External ID: ${response.externalId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python


from google.cloud import talent
import six

def get_tenant(project_id, tenant_id):
    """Get Tenant by name"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant 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")
    name = client.tenant_path(project_id, tenant_id)

    response = client.get_tenant(name=name)
    print(f"Name: {response.name}")
    print(f"External ID: {response.external_id}")

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器