我们的写入请求率几乎不超过每 100 秒 1 个请求,但从今天早上开始,我们开始在此方法的每个请求中都收到此 429 错误。我们的写入请求率为 3 次请求/100 次,在上午 8 点到 5 点期间,并且从未超过(每 5 分钟左右 9 次请求)。整个月总共有大约 50k 个请求。因此,远不及 Google 的任何默认配额限制。我们缺少什么?
响应主体是
"error": {
"code": 429,
"message": "Resource has been exhausted (e.g. check quota).",
"errors": [
{
"message": "Resource has been exhausted (e.g. check quota).",
"domain": "global",
"reason": "rateLimitExceeded"
}
],
"status": "RESOURCE_EXHAUSTED"
}
源代码的相关部分是(部分)代表控制台命令的 PHP 类:
class UpdatePresentations extends CommandUsingDb
{
/** @var Google_Service_Slides */
private $slides;
/** @var Google_Service_Slides_Request[] */
private $requests = [];
private function updateChart(Google_Service_Slides_Presentation $presentation, OutputProvider $outputProvider, Site $site)
{
// refresh charts in slides
foreach ($presentation->getSlides() as $index => $slide) {
foreach ($slide->getPageElements() as $element) {
/** @var Google_Service_Slides_PageElement $element */
$chart = $element->getSheetsChart();
if ($chart instanceof Google_Service_Slides_SheetsChart) {
$this->requests[] = new Google_Service_Slides_Request([
'refreshSheetsChart' => [
'objectId' => $element->getObjectId(),
],
]);
}
}
}
}
private function flush(Google_Service_Slides_Presentation $presentation)
{
if (empty($this->requests)) return;
$batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest();
$batchUpdateRequest->setRequests($this->requests);
$this->slides->presentations->batchUpdate($presentation->presentationId, $batchUpdateRequest);
}
}