获取服务帐号密钥

演示如何检索服务帐号密钥。

代码示例

C++

如需了解如何安装和使用 IAM 客户端库,请参阅 IAM 客户端库。如需了解详情,请参阅 IAM C++ API 参考文档

namespace iam = ::google::cloud::iam;
[](std::string const& key_name) {
  iam::IAMClient client(iam::MakeIAMConnection());
  auto response = client.GetServiceAccountKey(
      key_name, google::iam::admin::v1::ServiceAccountPublicKeyType::
                    TYPE_X509_PEM_FILE);
  if (!response) throw std::runtime_error(response.status().message());
  std::cout << "ServiceAccountKey successfully retrieved: "
            << response->DebugString() << "\n";
}

后续步骤

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