1

我们的写入请求率几乎不超过每 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);
   }
}
4

1 回答 1

1

问题出在您当时正在使用的文档中,尝试制作一个新文档,然后使用新的文档 ID 再次运行批量更新。这将解决 rateLimitExceeded 问题(实际上它甚至没有达到限制)。

于 2020-09-30T06:59:10.877 回答