【问题标题】:GitHub API limit exceeded: how to increase the rate limit in front-end appsGitHub API 超出限制:如何提高前端应用程序的速率限制
【发布时间】:2023-03-28 20:47:01
【问题描述】:

在向 GitHub API 发出一些 HTTP 请求后,它开始拒绝调用:

超过 xxx.xxx.xxx.xxx 的 API 速率限制。 (但这是好的 新闻:经过身份验证的请求获得更高的速率限制。查看 文档以获取更多详细信息。)

现在,a way to increase the unauthenticated rate limit for OAuth applications 涉及使用 client secret

当然,我们不想在前端应用程序的公共源代码上放置或client secret,正如文档所建议的那样:

注意:切勿与任何人共享您的客户端密码或将其包含在客户端浏览器代码中。仅将此处显示的方法用于服务器到服务器的调用。

所以我想知道在前端应用程序中解决速率限制问题的最佳方法是什么。

【问题讨论】:

    标签: web-applications frontend github-api


    【解决方案1】:

    这是一个相当老的问题,但是我设法将限制从 60 扩展到 5000。我将 client_secret 设置为 Header:Authorization - 这是我的私人应用程序,所以我不关心安全性。寻找解决方案我发现您可以将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())
    

    【讨论】:

      猜你喜欢
      • 2018-09-23
      • 1970-01-01
      • 2014-03-20
      • 2011-12-22
      • 2012-08-10
      • 2018-08-27
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      相关资源
      最近更新 更多