获取授权凭据
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您的应用必须有授权凭据才能使用 YouTube Reporting API 或 YouTube Analytics API。
本文档介绍了 Google API 控制台支持的不同类型的授权凭据。另外还介绍了如何查找或创建项目的授权凭据。
创建项目并选择 API 服务
- 打开 API 控制台中的“凭据”页面。
-
您可以通过该页面创建两种不同类型的凭据。
但是,YouTube Reporting API 和 YouTube Analytics API 的所有方法都需要 OAuth 2.0 授权。请按照以下说明生成 OAuth 2.0 凭据。
-
OAuth 2.0:当您的应用请求非公开用户数据时,该应用必须将 OAuth 2.0 令牌随请求一起发送。要获取令牌,您的应用应先发送客户端 ID(也可能需要发送客户端密钥)。您可以为网页应用、服务账号或已安装应用生成 OAuth 2.0 凭据。
如需了解详情,请参阅 OAuth 2.0 文档。
-
API 密钥:
您可以选择在请求中包含 API 密钥。
该密钥用于标识您的项目,并提供 API 访问权限、配额和报告。
请注意,YouTube Reporting API 和 YouTube Analytics API 的所有方法都需要 OAuth 2.0 授权。因此,您需要按照上述说明生成 OAuth 2.0 凭据。如果需要,您还可以发送 API 密钥,但这不是必需的。
此 API 支持多种类型的 API 密钥限制。如果您需要的 API 密钥尚不存在,请在控制台中创建 API 密钥,方法是:点击创建凭据
> API 密钥。您可以先对密钥设定相关限制,然后再在生产环境中使用密钥,方法是点击限制密钥,然后选择一项限制。
为保障 API 密钥的安全,请遵循以安全的方式使用 API 密钥的最佳做法。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-21。"],[[["\u003cp\u003eApplications need authorization credentials to use the YouTube Reporting API or the YouTube Analytics API.\u003c/p\u003e\n"],["\u003cp\u003eThe Google API Console supports different types of credentials, but the YouTube Reporting API and YouTube Analytics API require OAuth 2.0 authorization.\u003c/p\u003e\n"],["\u003cp\u003eOAuth 2.0 credentials, which involve a client ID and potentially a client secret, are needed for applications requesting private user data.\u003c/p\u003e\n"],["\u003cp\u003eAPI keys can be used to identify a project and provide API access, but are not necessary for the YouTube Reporting API and the YouTube Analytics API.\u003c/p\u003e\n"],["\u003cp\u003eYou can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.\u003c/p\u003e\n"]]],["To use the YouTube Reporting or Analytics APIs, applications need authorization credentials. Navigate to the Credentials page in the Google API Console to create them. While API keys can be created and optionally used, OAuth 2.0 credentials are required for all methods in these APIs. Generate OAuth 2.0 credentials, including a client ID and secret. API keys identify your project and can be restricted for security, but are not a replacement for OAuth 2.0 tokens.\n"],null,["# Obtain authorization credentials\n\nYour application must have authorization credentials to be able to use the YouTube Reporting API or the YouTube Analytics API.\n\nThis document describes the different types of authorization credentials that the [Google API Console](https://console.cloud.google.com/) supports. It also explains how to find or create authorization credentials for your project.\n\nCreate your project and select API services\n-------------------------------------------\n\n1. Open the [Credentials page](https://console.cloud.google.com/apis/credentials) in the API Console.\n2. The page allows you to create two different types of credentials. However, all of the methods for the YouTube Reporting API and the YouTube Analytics API require OAuth 2.0 authorization. Follow the instructions below to generate OAuth 2.0 credentials.\n - **OAuth 2.0:** Whenever your application requests private user\n data, it must send an OAuth 2.0 token along with the request. Your\n application first sends a client ID and, possibly, a client secret to\n obtain a token. You can generate OAuth 2.0 credentials for web\n applications, service accounts, or installed applications.\n\n For more information, see the [OAuth 2.0 documentation](https://developers.google.com/identity/protocols/OAuth2).\n - **API keys:**\n\n You have the option of including an API key with a request.\n\n The key identifies your project and provides API access, quota, and\n reports.\n\n\n Note that all of the methods for the YouTube Reporting API and the\n YouTube Analytics API require OAuth 2.0 authorization.\n\n\n For that reason, you need to follow the instructions above for\n generating OAuth 2.0 credentials. If you want, you can also send an\n API key, but that's not necessary.\n\n The API supports several types of restrictions on API keys. If the API key that you\n need doesn't already exist, then create an API key in the Console by\n clicking **[Create credentials](https://console.cloud.google.com/apis/credentials) \\\u003e API key** . You can restrict the key before using it\n in production by clicking **Restrict key** and selecting one of the\n **Restrictions**.\n\nTo keep your API keys secure, follow the [best practices for\nsecurely using API keys](//cloud.google.com/docs/authentication/api-keys)."]]