API 密钥
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档介绍了 API 密钥、何时使用 API 密钥、如何获取 API 密钥以及如何将其与适用于 .NET 的 Google API 客户端库结合使用。
简介
调用不访问用户私人数据的 API 时,您可以使用简单的 API 密钥。此密钥用于对您的应用进行身份验证,以便进行会计核算。您可以在控制台文档内详细了解 API 密钥。
注意:如果您确实需要访问用户私人数据,则必须使用 OAuth 2.0。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eAPI keys are used for authenticating applications when accessing public data, not private user data.\u003c/p\u003e\n"],["\u003cp\u003eYou can create and manage API keys through the Credentials page in the Google API Console.\u003c/p\u003e\n"],["\u003cp\u003eTo use an API key with the Google API Client Library for .NET, set the \u003ccode\u003eAPIKey\u003c/code\u003e property within the \u003ccode\u003eBaseClientService.Initializer\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eSecurely store and manage your API keys by adhering to Google's best practices.\u003c/p\u003e\n"]]],[],null,["This document describes API Keys, when to use them, how to acquire them,\nand how to use them with the Google API Client Library for .NET.\n\nIntroduction\n\n\nWhen calling an API that does not access private user data,\nyou can use a simple API key.\nThis key is used to authenticate your application for accounting purposes.\nYou can read more on [API keys](/console/help/using-keys) in the Console documentation.\n\n\n**Note** :\nIf you *do* need to access private user data, you must use\n[OAuth 2.0](/api-client-library/dotnet/guide/aaa_oauth).\n\nAcquiring API keys\n\n1. Open the [Credentials page](https://console.cloud.google.com/apis/credentials) in the API Console.\n2. Click **Create credentials \\\u003e API key** and select the appropriate key type.\n\nTo keep your API keys secure, follow the [best practices for\nsecurely using API keys](//cloud.google.com/docs/authentication/api-keys).\n\nUsing API keys\n\n\nTo use an API key, pass it to the\n[BaseClientService.Initializer `APIKey`](https://googleapis.dev/dotnet/Google.Apis/latest/api/Google.Apis.Services.BaseClientService.Initializer.html)\nproperty. The\n[Simple API Example](/api-client-library/dotnet/get_started#simple)\non the Get Started page provides a complete example that uses API keys.\n\n\nBy setting the `APIKey` property, you ensure that every call you make\nto the service will include the API key."]]