GMail API 用户速率在较长时间内受到限制

GMail API user rate-limited over extended period of time

我正在尝试进行一个简单的调用以获取帐户的电子邮件地址:

gmail().users().getProfile("me").execute().getEmailAddress();

然而它总是returns用户速率限制的响应:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 unknown
{
  "code" : 429,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "User-rate limit exceeded.  Retry after 2019-09-18T18:49:00.748Z",
    "reason" : "rateLimitExceeded"
  } ],
  "message" : "User-rate limit exceeded.  Retry after 2019-09-18T18:49:00.748Z"
}

无论在提到的时间之后等待,它总是返回此响应。在过去的 14 小时里,我让它每小时重试一次,但它仍然给出这个响应。我已经检查了我的 API 配额并确认该用户在该时间范围内没有其他使用 GMail 的情况。

我确实实施了指数退避,但是由于昨天我的脚本出现内部问题,短时间内有很多请求发送到 GMail API。正如预期的那样,它达到了速率限制,但似乎速率限制从那以后就没有 "turned off" 了。此用户帐户是否已列入黑名单?我怎样才能重新启动帐户并 运行?

也许答案是耐心,也许是运气。但是现在,在最初的请求问题出现大约 24 小时后,我的帐户似乎又可以使用了。

根据Gmail API documentation

Mail Sending Limits The Gmail API enforces the standard daily mail sending limits.

If these limits are exceeded a HTTP 429 Too Many Requests "User-rate limit exceeded" error mentioning "(Mail sending)" is returned with a time to retry.

email sending limits

are applied over a rolling 24-hour period.

这解释了为什么自最初问题后您需要等待 24 小时。

看看 email sending limits,这样您就知道超出了哪个配额,以后需要避免它。