Google Drive API超出了用户速率限制 [英] User Rate Limit Exceeded with google drive API

查看:254
本文介绍了Google Drive API超出了用户速率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google Drive API的基础上构建一个Web应用程序.基本上,Web应用程序显示照片和视频.媒体存储在Google云端硬盘文件夹中:通过身份验证后,应用程序会向Google云端硬盘API发出请求,以获取媒体的网址并显示每个网址.目前,我只有16张图像要显示.这些图像在应用程序中(用于演示)是手写的.

I'm building a web application on top of the Google Drive API. Basically, the web application displays photos and videos. The media is stored in a Google Drive folder: Once authenticated, the application makes requests to the Google Drive API to get an URL for the media and displays each one. For the moment, I have only 16 images to display. These images are hard-written in the application (for the demo).

我的应用程序访问Google云端硬盘API时遇到问题.确实,经过多次尝试,我在随机请求中遇到了此错误

I have encountered an issue with my application accessing Google Drive API. Indeed, after multiple tries, I've got this error for random requests

超出用户速率限制.用户请求率超过配置的项目配额. 您可以考虑重新评估API的预期每用户流量, 相应地调整项目配额限制. 您可以在API控制台中监控总配额使用情况并调整限制: https://console.developers.google.com /apis/api/drive.googleapis.com/quotas?project=XXXXXXX "

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: https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?project=XXXXXXX"

因此,我查看了API控制台,没有发现什么特别之处,我没有超出速率限制.也许我使用了错误的Google API,但实际上我不知道...

So I looked the API console and saw nothing special, I don't exceed the rate limit according to me. Maybe I use wrong the google API, I don't know in fact...

我遵循了Google Drive API文档,以检查我是否做错了什么.对于每个API请求,该请求都包含访问令牌,因此它应该可以正常工作!

I followed the Google Drive API documentation to check whether I did something wrong. For each API request, the request contains the access token, so it should work correctly !

该应用程序的演示可用: https://poc-drive-api.firebaseapp.com

A demonstration of the app is available: https://poc-drive-api.firebaseapp.com

源代码也可用: https://github.com/Mcdostone/poc -google-drive-api (文件App.js)

The source code is also available: https://github.com/Mcdostone/poc-google-drive-api (file App.js)

推荐答案

我正在使用 limiter 库来强制执行每100秒1000个查询"的限制,但是我仍然遇到403错误.最后,我偶然发现了页,其中提到了:

I was using the limiter library to enforce the "1000 queries per 100 seconds" limit, but I was still getting 403 errors. I finally stumbled upon this page where it mentions that:

在API控制台中,有一个类似的配额,称为每用户每100秒请求数.默认情况下,它设置为每位用户每100秒100个请求,并且可以调整为最大值1,000.但是对API的请求数限制为每位用户每秒最多10个请求.

In the API Console, there is a similar quota referred to as Requests per 100 seconds per user. By default, it is set to 100 requests per 100 seconds per user and can be adjusted to a maximum value of 1,000. But the number of requests to the API is restricted to a maximum of 10 requests per second per user.

因此,我将限制器库更新为每秒仅允许10个请求,而不是每100秒仅允许1,000个请求,它的工作原理很吸引人.

So I updated the limiter library to only allow 10 requests every second instead of 1,000 every 100 seconds and it worked like a charm.

const RateLimiter = require('limiter').RateLimiter;

const limiter = new RateLimiter(10, 1000);

这篇关于Google Drive API超出了用户速率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆