在向 GitHub API 发出一些 HTTP 请求后,它开始拒绝调用:
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.)
现在,有a way to increase the unauthenticated rate limit for OAuth applications这涉及使用
client secret
.当然我们不想放或
client secret
在前端应用程序的公共(public)源代码上,文档还建议: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.
所以我想知道解决前端应用程序中速率限制问题的最佳方法是什么。
最佳答案
这是一个很老的问题,但是我设法将限制从 60 扩展到 5000。我把 client_secret
至Header:Authorization
- 这是我的私有(private)应用程序,所以我不关心安全性。寻找解决方案我发现你可以把 mode='cors'
至initRequest
你可以发送CORS
对 GitHub API 的请求。
TypeScript 类示例:
Typscript 简单类示例
例如:
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())
关于web-applications - GitHub API 限制超出 : how to increase the rate limit in front-end apps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44395747/