GitHub API limit exceeded: how to increase the rate limit in front-end apps

拜拜、爱过 提交于 2019-12-10 23:31:53

问题


After some HTTP requests to the GitHub API, it starts refusing the calls saying:

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.)

Now, there is a way to increase the unauthenticated rate limit for OAuth applications which involves using the 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.


回答1:


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 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())


来源:https://stackoverflow.com/questions/44395747/github-api-limit-exceeded-how-to-increase-the-rate-limit-in-front-end-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!