How to set Google API key restriction - HTTP referrers

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

Google API key restriction - HTTP referrers

I put my Azure website url xxxx.scm.azurewebsites.net there but doesn't work (Google Places API Web Service stops working).

localhost:44300 doesn't work either.

I have to set key restriction to 'None', then Google Places API Web Service will work.

What did I do wrong?

回答1:

Web Service is supposed to be executed on backend servers, so the correct restriction for web services is IP restriction.

HTTP referer restriction is used for client side services like Google Maps JavaScript API, it won't work with web services.



回答2:

To accept requests over localhost and HTTP (HTTP referrers) in Google Maps API, follow the instructions in the javascript console printed out by the Google Maps API (it tells you exactly what to do):

Google Maps API error: RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error

Your site URL to be authorized: http://localhost:3000/en

The line Your site URL to be authorized indicates which value you have to set up in Accept requests from these HTTP referrers (websites)

In this case, e.g. for a Ruby on Rails App, it is:

http://localhost:3000/en 

But you can do better, by using asterisks for wildcards:

*localhost:3000/* 

To set the value to localhost:3000/* does not work!



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