我需要能够正确捕获和处理从Gmail API返回的全局速率限制错误。如何区分每个用户的速率限制错误和全局速率限制错误?
我为此没有找到任何明确的文档,但是我假设响应有效负载中的domain
属性将说成global
而不是usageLimits
。谁能验证这是正确的吗?
下面我假设全局速率限制错误的示例如下
{
"error": {
"errors": [
{
"domain": "global",
"message": "Rate Limit Exceeded",
"reason": "rateLimitExceeded",
}
],
"code": 403,
"message": "Rate Limit Exceeded"
}
}
答案 0 :(得分:0)
您可以通过强制用户和域的配额限制率错误来检查此问题。如果您是管理员,则可以在Google Cloud Platform控制台(console.cloud.google.com)中为每个项目和每个API编辑总配额率限制和每个用户。阅读有关如何编辑配额限制的说明[1]。
您可以在此处[2]看到每种Gmail API方法使用的“配额单位”。
关于错误消息,我像前面解释的那样强加了两个限制,并得到了这个信息:
对于用户:
"errors": [
"domain": "usageLimits",
"reason": "userRateLimitExceeded",
"message": "User Rate Limit Exceeded. Rate of requests for user exceed configured project quota. You may consider re-evaluating expected per-user traffic to the API and adjust project quota limits accordingly. You may monitor aggregate quota usage and adjust limits in the API Console: XXXXX",
"extendedHelp": "XXXXX"
]
在我放置XXXXX的位置,有一个URL可以修改该项目的配额限制。
对于域(总计):
"errors": [
"domain": "usageLimits",
"reason": "rateLimitExceeded",
"message": "Rate Limit Exceeded"
]
[1] https://cloud.google.com/apis/docs/capping-api-usage
[2] https://developers.google.com/gmail/api/v1/reference/quota