超过GitHub API限制:如何提高前端应用程序的速率限制 [英] GitHub API limit exceeded: how to increase the rate limit in front-end apps
问题描述
对GitHub API的一些HTTP请求之后,它开始拒绝调用,说:
After some HTTP requests to the GitHub API, it starts refusing the calls saying:
超出了xxx.xxx.xxx.xxx的API速率限制. (但这是好事 新闻:认证请求获得更高的速率限制.签出 文档以获取更多详细信息.)
API rate limit exceeded for xxx.xxx.xxx.xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
现在,有一种方式增加OAuth应用程序的未经身份验证的速率限制,其中涉及使用client secret
.
Now, there is a way to increase the unauthenticated rate limit for OAuth applications which involves using the client secret
.
当然,我们也不想在前端应用程序的公共源代码上放置或client secret
,正如文档所建议的那样:
Of course we don't want to put or client secret
on the public source code of a front-end app, as also the documentation recommends:
注意:切勿与任何人共享您的客户机密,也不要将其包含在客户端浏览器代码中.仅将此处显示的方法用于服务器到服务器的调用.
Note: Never share your client secret with anyone or include it in client-side browser code. Use the method shown here only for server-to-server calls.
所以我想知道在前端应用程序中解决速率限制问题的最佳方法是什么.
so I was wondering what's the best way to solve the issue of the rate limit in a front end application.
推荐答案
这是一个很老的问题,但是我设法将限制从60扩展到5000.我将client_secret
放入Header:Authorization
-这是我的私人应用程式,因此我不在乎安全性.在寻找解决方案时,我发现可以将mode='cors'
放入initRequest
,并且可以将CORS
请求发送到GitHub API.
It is quite old question, however I managed to extend the limit from 60 to 5000. I am putting the client_secret
to Header:Authorization
- it is my private app, so I do not care about the security. Looking for the solution I have found that you can put mode='cors'
to initRequest
and you are able to send CORS
request to GitHub API.
TypeScript类示例: 打字稿简单类实例 例如:
TypeScript class example: Typscript simple class exmaple e.g:
export default class AppRequestInit implements RequestInit {
public method: string = 'GET';
public headers: Headers = new Headers();
public mode: RequestMode = 'cors';
constructor() {
this.headers.set('Content-Type', 'application/json');
this.headers.append('Authorization', 'token XXXXXXXXXXXXXXXX');
}
}
usage: fetch('https://api.github.com/users/USERNAME', new AppRequestInit())
这篇关于超过GitHub API限制:如何提高前端应用程序的速率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!