Protecting YouTube v3 API key in a client-side application

。_饼干妹妹 提交于 2019-11-30 20:19:14

This was due to a quota cost increase, it's temporarily reverted. We'll announce cost changes in http://apiblog.youtube.com/ and https://developers.google.com/youtube/v3/revision_history going forward.

Don't think it is a malicious user. I think something's wrong on YouTube's side, since I'm seeing exactly the same issue with API requests made from my app

You can use restriction to secure your API Key.

Use the REFERERS attribute of the public API key. Go to your project in console developers -> API&Auth -> Credentials

  • If you use Key for browser applications, REFERERS is a reference to a domain.
  • If you use Server key, REFERERS is a reference to a IP. (ip of your server for example)

For example, if you use github.io to make live demo of an application, REFERERS will point on http://user.github.io/*

You can read more register your application

  • Use a server key if your application runs on a server. Do not use this key outside of your server code. For example, do not embed it in a web page. To prevent quota theft, restrict your key so that requests are only allowed from your servers' source IP addresses.

  • Use a browser key if your application runs on a client, such as a web browser. To prevent your key from being used on unauthorized sites, only allow referrals from domains you administer.

A screen to help you :

It appears to be a major bug. Same problem here - quota usage spiked like crazy starting on Sept. 3 and requests now cost WAY more than the documentation states.

Someone reported it as a defect in their bug tracking system. I suggest everyone affected go there and star the defect to help call attention to it:

I propose the following ideas:

  • You can make sure the user accessing your page is a human (with Captcha, etc.)
  • Hide your API call behind an AJAX call that is triggered by your front-end (like GET /callgoogleapi);
  • The handler of AJAX call can set a frequency threshold, i.e. 2 requests per second. If too fast, the API call is not made, and AJAX replies a message like "User operation too fast".

That is correct. When you make your key make sure you use the REFERERS so that even if they do get your key it will not work for them!

We also see this error, it seems to be too large deviations. results Overview is 813.844, but the APIs are Used 49,379,348 of 50,000,000 requests today

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