限制和配额
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
限制和配额可保护 Google 的基础架构,防止被自动化流程以不当方式使用 Reports API。从某个 API 发出过多请求的原因可能是无害的拼写错误,也可能是由于系统设计效率低下、进行不必要的 API 调用造成的。无论是什么原因,在来自特定来源的流量达到特定水平时,都有必要将其屏蔽,以保证 Google Workspace 系统的整体运行状况。它可确保一个开发者的行为不会对更广泛的社区产生负面影响。
万一您的 API 请求失败,您会收到 HTTP 状态代码响应。状态代码 403 包含有关输入不正确的错误信息,而 HTTP 状态代码 503 则包含指示已超出哪些 API 配额的错误信息。通过这些响应,您的自定义应用将能够检测这些错误并采取适当的措施。
如果您的请求需要在固定的时间段内完成,请并行发送请求,或在 Java 或 C# 应用中使用多个线程。并行请求的一个示例是请求来自不同用户的小批量电子邮件,而不是同时添加或移除一个用户中的大量电子邮件。对于会话,请尝试先创建 10 个会话,每个用户电子邮件地址对应一个会话。请注意,线程建议需要权衡取舍,并且并非适用于所有 API 情况。如果请求数过高,将会发生配额错误。
对于所有基于时间的错误(每个线程最多持续 N 秒 N 秒),尤其是 503 状态代码错误,我们建议您的代码捕获异常,并使用指数退避算法算法等待一小段延迟,然后再重试失败的调用。一个线程的 Reports API 示例是等待 5 秒钟,然后重试失败的调用。如果请求成功,请对其他线程重复此模式。如果第二个请求未成功,您的应用应根据请求频率缩容,直到调用成功为止。例如,将初始的 5 秒延迟增加到 10 秒,然后再次重试失败的呼叫。此外,您需要决定重试次数上限。例如,在您的应用向用户返回错误之前,使用不同的延迟时间重试请求 5 到 7 次。
API 限制类别 |
限制 |
报告 QPS 和 QPD 比率 |
该 API 会限制 Google Cloud 项目的请求数。Google Cloud 控制台中设置的默认值为每个 Google Cloud 项目每位用户每分钟 2,400 次查询。
您可以在 Google Cloud 项目的 Admin SDK API 配额页面中提高此上限。 如果超出这些限制,服务器将返回 HTTP 503 状态代码。重试请求时请使用指数退避算法算法。
|
API 配额类别 |
配额 |
maxResults |
API 响应的每个页面中列出的记录数量为从 1 到 1000 个事件。默认值为 1,000 条记录。
|
其他类型的限制 |
限制和准则 |
数据格式,默认 |
默认的数据格式为 JSON。该 API 还支持 Atom 格式。
|
未经授权的请求 |
Google 不允许向 API 发出未经授权的请求。如果未提供授权令牌,请求会被视为未获得授权。如需了解详情,请参阅向请求授权。 |
警告消息 |
- 数据不可用:此应用程序及当天的数据不可用,且以后不可用。
- 可显示部分数据:未来可能会提供此应用及相应日期的数据。
如需了解 Reports API 的警告语法,请参阅适用于客户和用户的 API 参考文档。
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-25。
[null,null,["最后更新时间 (UTC):2025-03-25。"],[],[],null,["# Limits and Quotas\n\nLimits and quotas protect the Google infrastructure from an automated process that uses the Reports API in an inappropriate way. Excessive requests from an API might result from a harmless typo, or might result from an inefficiently designed system that makes needless API calls. Regardless of the cause, blocking traffic from a specific source once it reaches a certain level is necessary for the overall health of the Google Workspace system. It ensures that one developer's actions cannot negatively impact the larger community.\n\nIn the unlikely event that your API request fails, you'll receive an HTTP status code response. A status code of 403 has error information about incorrect input and an HTTP status code of 503 has error information indicating which API quotas have been exceeded. These responses allow your custom application to detect these errors and take appropriate action.\n\nIf your requests need to be completed in a fixed period of time, send your requests in parallel or use multiple threads in your Java or C# application. An example of parallel requests is requesting small batches of emails from different users rather than adding or removing lots of emails from one user simultaneously. In the case of threads, try starting with 10 threads, one thread per user email. Note, the thread recommendation has trade-offs and is not useful for all API situations. If the number of requests gets too high, quota errors will occur.\n\nFor all errors that are time based (maximum of \u003cvar translate=\"no\"\u003eN\u003c/var\u003e things for \u003cvar translate=\"no\"\u003eN\u003c/var\u003e seconds per thread), especially the 503 status code errors, we recommend your code catch the exception and, using an [exponential backoff](http://wikipedia.org/wiki/Truncated_binary_exponential_backoff) algorithm, wait for a small delay before retrying the failed call. A Reports API example for one thread is to wait 5 seconds and retry the failed call. If the request is successful, repeat this pattern for the other threads. If the second request is not successful, your application should scale back on the frequency of the request until a call is successful. For example, increase the initial 5 second delay to 10 seconds and retry your failed call again. Also, decide on a retry limit. For example retry a request 5 to 7 times with different delay times before your application returns an error to the user.\n\n| API Limit Categories | Limits |\n|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Report QPS and QPD rates | The API limits the number of requests for your Google Cloud project. The default value set in the Google Cloud console is 2,400 queries per minute per user per Google Cloud project. You can increase this limit from the [Admin SDK API Quotas page](https://console.cloud.google.com/apis/api/admin.googleapis.com/quotas) of your Google Cloud project. If these limits are exceeded, the server returns an HTTP 503 status code. Use the [exponential backoff](http://wikipedia.org/wiki/Truncated_binary_exponential_backoff) algorithm when retrying your requests. |\n| maxResults | The number of records listed in each page of an API's response is from 1 to 1000 events. The default is 1000 records. |\n\n\n| Other Types of Limits | Limitations and Guidelines |\n|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Data format, default | The default data format is JSON. The API also supports the Atom format. |\n| Unauthorized requests | Google does not allow unauthorized requests to the API. A request is considered unauthorized if no authorization token is provided. For more information, see [Authorizing requests](/workspace/admin/reports/v1/guides/authorizing). |\n| Warning messages | - Data not available: The data for this application and for this date is not available and will not be available in the future. - Partial data available: The data for this application and for this date may be available in the future. For the Reports API's warning syntax, see the API Reference for [customers](/workspace/admin/reports/v1/reference/customerUsageReports/get) and for [users](/workspace/admin/reports/v1/reference/userUsageReport/get). |"]]