GitHub API 超出限制:如何提高前端应用程序的速率限制 [英] GitHub API limit exceeded: how to increase the rate limit in front-end apps

查看:28
本文介绍了GitHub API 超出限制:如何提高前端应用程序的速率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在向 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 类示例:Typscript 简单类示例例如:

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屋!

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