web-applications - GitHub API 限制超出 : how to increase the rate limit in front-end apps

标签 web-applications frontend github-api

在向 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_secretHeader: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/

相关文章:

javascript - 在浏览器布局中为响应式图像保留空间(防止回流)

javascript - 在正文中嵌入 <script> 标签..有什么影响?

javascript - 带有 JavaScript 的 NFC

java - 如何开始使用 Java 构建 Web 应用程序?

java - 是否可以为 war 文件提供安全性?

twitter-bootstrap - 使用 NPM 和 SASS 自定义 Bootstrap 4 的正确方法?

javascript - 我的代码在 $(document).ready() 函数中不起作用。谁能帮我理解为什么?

oauth - 撤销 OAuth 访问 token 导致 404 未找到

ruby-on-rails - GitHub API : Cannot reliably add files to repository

javascript - 使用nodejs通过api在github中创建Issue并请求: response is undefined