Dataset-Details abrufen.
Dokumentationsseiten mit diesem Codebeispiel
Das Codebeispiel im Kontext finden Sie in der folgenden Dokumentation:
Codebeispiel
Go
import (
"context"
"fmt"
"io"
healthcare "google.golang.org/api/healthcare/v1"
)
// getDataset gets a dataset.
func getDataset(w io.Writer, projectID, location, datasetID string) error {
ctx := context.Background()
healthcareService, err := healthcare.NewService(ctx)
if err != nil {
return fmt.Errorf("healthcare.NewService: %v", err)
}
datasetsService := healthcareService.Projects.Locations.Datasets
name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", projectID, location, datasetID)
resp, err := datasetsService.Get(name).Do()
if err != nil {
return fmt.Errorf("Get: %v", err)
}
fmt.Fprintf(w, "Name: %s\n", resp.Name)
fmt.Fprintf(w, "Time zone: %s\n", resp.TimeZone)
return nil
}
Java
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.Dataset;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
public class DatasetGet {
private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
public static void datasetGet(String datasetName) throws IOException {
// String datasetName =
// String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dataset-id");
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
// Create request and configure any parameters.
Datasets.Get request = client.projects().locations().datasets().get(datasetName);
// Execute the request and process the results.
Dataset dataset = request.execute();
System.out.println("Dataset retrieved: \n" + dataset.toPrettyString());
}
private static CloudHealthcare createClient() throws IOException {
// Use Application Default Credentials (ADC) to authenticate the requests
// For more information see https://cloud.google.com/docs/authentication/production
GoogleCredentials credential =
GoogleCredentials.getApplicationDefault()
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer =
request -> {
new HttpCredentialsAdapter(credential).initialize(request);
request.setConnectTimeout(60000); // 1 minute connect timeout
request.setReadTimeout(60000); // 1 minute read timeout
};
// Build the client for interacting with the service.
return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
.setApplicationName("your-application-name")
.build();
}
}
Node.js
const {google} = require('googleapis');
const healthcare = google.healthcare('v1');
const getDataset = async () => {
const auth = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
google.options({auth});
// TODO(developer): uncomment these lines before running the sample
// const cloudRegion = 'us-central1';
// const projectId = 'adjective-noun-123';
// const datasetId = 'my-dataset';
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
const request = {name: parent};
const dataset = await healthcare.projects.locations.datasets.get(request);
console.log(dataset.data);
};
getDataset();
Python
def get_dataset(project_id, cloud_region, dataset_id):
"""Gets any metadata associated with a dataset."""
client = get_client()
dataset_name = 'projects/{}/locations/{}/datasets/{}'.format(
project_id, cloud_region, dataset_id)
datasets = client.projects().locations().datasets()
dataset = datasets.get(name=dataset_name).execute()
print('Name: {}'.format(dataset.get('name')))
print('Time zone: {}'.format(dataset.get('timeZone')))
return dataset
Nächste Schritte
Informationen zum Suchen und Filtern von Codebeispielen für andere Google Cloud-Produkte finden Sie im Google Cloud-Beispielbrowser