部分 Google Cloud API 尚未提供所有语言的 Cloud 客户端库。如果您要使用其中一种 API 并且没有适用于您首选语言的 Cloud 客户端库,您仍然可以使用以前样式的客户端库,即 Google API 客户端库。如果您要升级已使用这些库的项目,也可以使用这些库。此类库具有以下特点:
Firebase 是 Google 上用于在移动设备上构建应用的解决方案。它提供了一个包含客户端代码的 SDK,让您可以从 iOS、Android 和 Web 应用访问与移动设备相关的 Cloud API。如需了解受支持的 Cloud API 以及如何开始使用 Firebase,请参阅 Firebase 文档。
使用您自己的客户端代码
如果您是经验丰富的开发者,并且 Google 的客户端库无法满足您的特定需求,您可以编写自己的自定义代码来直接访问服务的低层级服务 API。
REST/HTTP API
所有 Cloud API 都公开了一个简单的传统 JSON/REST 接口。如果您需要编写自己的自定义代码以使用第三方 HTTP 客户端库来直接访问 REST API,您可以在 HTTP 准则中找到关于 Cloud API 如何使用不同的 HTTP 版本和实现的更多信息。
gRPC API
gRPC 是一种与语言无关、与平台无关的开源远程过程调用 (RPC) 系统,最初由 Google 开发。您可以在 grpc.io 上了解相关信息。启用 gRPC 的 Cloud API 通常同时具有 REST 和 RPC 接口,因此启用 gRPC 的 API 客户端不仅可以使用 JSON over HTTP 与 REST 接口通信,还可以使用 Protocol Buffers 和 gRPC over HTTP2 与 RPC 接口通信。您可以通过查看“API 和参考”部分来了解 API 是否启用了 gRPC。
如果 Cloud API 启用了 gRPC,您可以使用 gRPC 支持的语言为其生成自己的 gRPC 客户端库。为此,您需要 API 的协议缓冲服务定义(通常可从 GitHub 上的代码库获得)。然后,您可以按照 grpc.io 上对您的首选语言的说明生成并使用您的客户端。
如果您不想生成自己的 gRPC 代码,您仍然可以从 gRPC 中受益:越来越多的启用了 gRPC 的 API 的 Cloud 客户端库“在后台”使用 gRPC 与 Google 的服务器进行通信。这在吞吐量和 CPU 使用率方面明显更为高效:与 JSON REST API 相比,使用 gRPC 访问 API 可以将每个 CPU 的吞吐量提高至多系数 10。Google 计划将尽可能多的 Cloud 客户端库升级到 gRPC;与此同时,您仍将获得 Google 客户端库代码的所有其他好处。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eCloud Client Libraries are the recommended method for accessing Cloud APIs programmatically, offering idiomatic code, consistent style, and handling low-level server communication.\u003c/p\u003e\n"],["\u003cp\u003eGoogle API Client Libraries serve as an alternative for APIs that lack Cloud Client Libraries in certain languages, providing access to the REST interface only, but with autogenerated interface code.\u003c/p\u003e\n"],["\u003cp\u003eFirebase SDK provides client code for accessing mobile-relevant Cloud APIs from iOS, Android, and Web applications, which is the go to solution for mobile device application development.\u003c/p\u003e\n"],["\u003cp\u003eExperienced developers can opt to write their own custom code to directly interact with the service's lower-level APIs, using the JSON/REST interface or gRPC.\u003c/p\u003e\n"],["\u003cp\u003egRPC-enabled Cloud APIs offer a performance advantage through the use of protocol buffers and gRPC over HTTP2, with some Cloud Client Libraries leveraging gRPC for improved efficiency.\u003c/p\u003e\n"]]],[],null,["# Client libraries explained\n\nClient libraries make it easier to access\n[Google Cloud APIs](/apis/docs/overview)\nfrom a supported language. While you can use Google Cloud APIs directly\nby making raw requests to the server, client libraries provide simplifications\nthat significantly reduce the amount of code you need to write.\n\nThis document explains the different types of client libraries that Google\nprovides for Cloud APIs. You can also find out more about the available\nlibraries for your product or language of choice in the product or language's\ndocumentation.\n\nCloud Client Libraries\n----------------------\n\n[Cloud Client Libraries](/apis/docs/cloud-client-libraries)\nare the recommended option for accessing Cloud APIs programmatically, where\navailable. Cloud Client Libraries use the latest client library model and:\n\n- Provide idiomatic code in each language to make Cloud APIs simple and intuitive to use.\n- Provide a consistent style across client libraries to simplify working with multiple Cloud services.\n- Handle all the low-level details of communication with the server, including [authenticating with Google](/docs/authentication/client-libraries).\n- Can be installed using familiar package management tools such as `npm` and `pip`.\n- In some cases, give you performance benefits by using gRPC. For more information, see the [gRPC APIs](#grpc_apis).\n\nYou can find installation instructions and reference material for the\nCloud Client Library on the Client Libraries page for the\n[Cloud API](/apis/docs/overview)s\nyou're using. You can find links to get started with the\nCloud Client Libraries and their reference documentation on the\n[Cloud Client Libraries page](/apis/docs/cloud-client-libraries).\n\nTry it for yourself\n-------------------\n\n\nIf you're new to Google Cloud, create an account to evaluate how our\nproducts perform in real-world scenarios. New customers also get $300 in\nfree credits to run, test, and deploy workloads.\n[Get started for free](https://console.cloud.google.com/freetrial)\n\nGoogle API Client Libraries\n---------------------------\n\nA few Google Cloud APIs don't have Cloud Client Libraries available in all\nlanguages. If you want to use one of these APIs and there is no\nCloud Client Library for your preferred language, you can still use the previous\nstyle of client library, called\n[Google API Client Libraries](https://developers.google.com/api-client-library/).\nYou might also use these libraries if you're upgrading a project that already\nuses them. These libraries:\n\n- Provide access to the API's REST interface only; gRPC is not supported.\n- Have autogenerated interface code that might not be as idiomatic as the Cloud Client Libraries.\n- Handle all the low-level details of communication with the server, including [authenticating with Google](/docs/authentication/client-libraries).\n- Can be installed using familiar package management tools such as `npm` and `pip`.\n\nThese libraries are linked on the Client Libraries page for the relevant Cloud\nAPIs.\n\nUsing the Firebase mobile platform\n----------------------------------\n\nFirebase is the Google-wide solution for building applications on mobile\ndevices. It offers an SDK with client code that lets you access mobile-relevant\nCloud APIs from iOS, Android, and Web apps. For information on the supported\nCloud APIs and how to get started with Firebase, see the\n[Firebase documentation](https://firebase.google.com/docs).\n\nUsing your own client code\n--------------------------\n\nIf you're an experienced developer and Google's client libraries don't meet your\nspecific needs, you can write your own custom code to access the service's\nlower-level service APIs directly.\n\n### REST/HTTP APIs\n\nAll Cloud APIs expose a simple traditional JSON/REST interface. If you need to\nwrite your own custom code to directly access the REST API using a third-party\nHTTP client library, you can find out more about how Cloud APIs work with\ndifferent HTTP versions and implementations in the\n[HTTP Guidelines](/apis/docs/http).\n\n### gRPC APIs\n\ngRPC is a language-neutral, platform-neutral, open source, remote procedure call\n(RPC) system initially developed at Google. You can find out about it at\n[grpc.io](http://www.grpc.io/).\ngRPC-enabled Cloud APIs generally have both REST and RPC interfaces, so rather\nthan just using JSON over HTTP to talk to the REST interface, gRPC-enabled API\nclients can also use\n[protocol buffers](https://developers.google.com/protocol-buffers/)\nand gRPC over HTTP2 to talk to the RPC interface. You can find out if an API is\ngRPC-enabled by checking its APIs and Reference section.\n\nIf a Cloud API is gRPC-enabled, you can generate your own gRPC client libraries\nfor it in any gRPC-supported language. To do this, you'll need the API's\n[protocol buffers](https://developers.google.com/protocol-buffers/)\nservice definition (typically available from\n[the repository on GitHub](https://github.com/googleapis/googleapis)).\nYou can then follow the instructions for your preferred language on\n[grpc.io](http://www.grpc.io/)\nto generate and use your client.\n\nIf you don't want to generate your own gRPC code, you can still benefit from\ngRPC: a growing number of Cloud Client Libraries for gRPC-enabled APIs use gRPC\n\"under the hood\" to communicate with Google's servers. This is significantly\nmore efficient in terms of throughput and CPU usage --- accessing an API\nusing gRPC can increase throughput per CPU by as much as a factor of 10 compared\nto the JSON REST API. Google plans to upgrade as many Cloud Client Libraries as\npossible to gRPC; in the meantime, you'll still get all the other advantages of\nGoogle's client library code.\n\nOther ways to access Cloud APIs\n-------------------------------\n\nIf you don't want to access an API programmatically, you can access some\nof the same functionality using the tools in\n[Google Cloud CLI](/sdk/docs) or using the\n[Google Cloud console](https://console.cloud.google.com/)."]]