取得執行個體詳細資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
根據目前專案中的執行個體 ID 取得執行個體詳細資料。
深入探索
如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:
程式碼範例
C++
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
C#
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples for retrieving instance details using an instance ID within the current Google Cloud project.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples demonstrate how to get instance details in various programming languages, including C++, C#, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach language section includes instructions on how to authenticate using Application Default Credentials and how to install the client library for Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets show how to access and print details like the instance ID, display name, labels, state, and type.\u003c/p\u003e\n"],["\u003cp\u003eA link to the Google Cloud sample browser is provided to discover more code examples for Google Cloud products.\u003c/p\u003e\n"]]],[],null,["Get instance details given the instance ID in the current project.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Get instance information](/bigtable/docs/get-instance-information)\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id, std::string const& instance_id) {\n std::string instance_name = cbt::InstanceName(project_id, instance_id);\n StatusOr\u003cgoogle::bigtable::admin::v2::Instance\u003e instance =\n instance_admin.GetInstance(instance_name);\n if (!instance) throw std::move(instance).status();\n std::cout \u003c\u003c \"GetInstance details : \" \u003c\u003c instance-\u003eDebugString() \u003c\u003c \"\\n\";\n }\n\nC#\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Initialize request argument(s).\n GetInstanceRequest request = new GetInstanceRequest\n {\n InstanceName = new InstanceName(projectId, instanceId)\n };\n try\n {\n // Make Request.\n Console.WriteLine(\"Waiting for operation to complete...\");\n Instance respond = bigtableInstanceAdminClient.GetInstance(request);\n }\n catch (Exception ex)\n {\n Console.WriteLine($\"Exception retreiving {instanceId} instance\");\n Console.WriteLine(ex.Message);\n }\n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n Instance instance = null;\n try {\n instance = adminClient.getInstance(instanceId);\n System.out.println(\"Instance ID: \" + instance.getId());\n System.out.println(\"Display Name: \" + instance.getDisplayName());\n System.out.print(\"Labels: \");\n Map\u003cString, String\u003e labels = instance.getLabels();\n for (String key : labels.keySet()) {\n System.out.printf(\"%s - %s\", key, labels.get(key));\n }\n System.out.println(\"\\nState: \" + instance.getState());\n System.out.println(\"Type: \" + instance.getType());\n } catch (NotFoundException e) {\n System.err.println(\"Failed to get non-existent instance: \" + e.getMessage());\n }\n\nNode.js\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const [instances2] = await bigtable.instance(instanceID).get();\n console.log(`Instance ID: ${instances2.id}`);\n console.log(`Instance Meta: ${JSON.stringify(instances2.metadata)}`);\n\nPHP\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\ApiCore\\ApiException;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Client\\BigtableInstanceAdminClient;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\GetInstanceRequest;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Instance\\State;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Instance\\Type;\n\n /**\n * Get a Bigtable instance\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n */\n function get_instance(\n string $projectId,\n string $instanceId\n ): void {\n $instanceAdminClient = new BigtableInstanceAdminClient();\n $instanceName = $instanceAdminClient-\u003einstanceName($projectId, $instanceId);\n\n printf('Fetching the Instance %s' . PHP_EOL, $instanceId);\n try {\n $getInstanceRequest = (new GetInstanceRequest())\n -\u003esetName($instanceName);\n $instance = $instanceAdminClient-\u003egetInstance($getInstanceRequest);\n } catch (ApiException $e) {\n if ($e-\u003egetStatus() === 'NOT_FOUND') {\n printf('Instance %s does not exists.' . PHP_EOL, $instanceId);\n return;\n }\n throw $e;\n }\n\n printf('Printing Details:' . PHP_EOL);\n\n // Fetch some commonly used metadata\n printf('Name: ' . $instance-\u003egetName() . PHP_EOL);\n printf('Display Name: ' . $instance-\u003egetDisplayName() . PHP_EOL);\n printf('State: ' . State::name($instance-\u003egetState()) . PHP_EOL);\n printf('Type: ' . Type::name($instance-\u003egetType()) . PHP_EOL);\n printf('Labels: ' . PHP_EOL);\n\n $labels = $instance-\u003egetLabels();\n\n // Labels are an object of the MapField class which implement the IteratorAggregate, Countable\n // and ArrayAccess interfaces so you can do the following:\n printf(\"\\tNum of Labels: \" . $labels-\u003ecount() . PHP_EOL);\n printf(\"\\tLabel with a key(dev-label): \" . ($labels['dev-label'] ?? 'N/A') . PHP_EOL);\n\n // we can even loop over all the labels\n foreach ($labels as $key =\u003e $val) {\n printf(\"\\t$key: $val\" . PHP_EOL);\n }\n }\n\nPython\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n print(\n \"\\nName of instance: {}\\nLabels: {}\".format(\n instance.display_name, instance.labels\n )\n )\n\nRuby\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # instance_id = \"my-instance\"\n instance = bigtable.instance instance_id\n puts \"Get Instance id: #{instance.instance_id}\"\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]