Browser API API keys cannot have restrictions on links when used with this API

I am trying to program geocoding. I created an API key, but when I add it to the code of my site, I get nothing, however, when I do not use the API, everything works fine. When I submit:

https://maps.googleapis.com/maps/api/geocode/json?address=".$adres."&key=KLUCZ_XXX 

I get the answer:

 Browser API keys cannot have referer restrictions when used with this API. 

If I use:

 https://maps.googleapis.com/maps/api/geocode/json?address=".$adres" 

The result is correct, but the number of requests is limited per day.

Key restriction: HTTP (Web) referrals - installation in the domain from which the request is requested. The Google Maps Geocoding API is enabled.

Do I need to activate the API key elsewhere?

+5
source share
1 answer

It looks like you can make an API server server. Today I came across this question. Since you have placed a referrer constraint on your API key, it will be limited to the execution of web services APIs in the browser, including the geocoding APIs. This did not work for me, even if I manually set up the referrer in the request headers. You can find other web services APIs on this page: https://developers.google.com/maps/web-services/

Important. If you use any web services APIs with an API key that has referent reviews, your requests will fail with the error message: "API keys cannot have restrictions on links when used with this API." You must switch to using server restrictions.

You need to create a separate key for server-side use. You can change your restriction from browser restriction to server restriction using IP addresses to restrict access, and not for browser links.

See this section in the Maps API FAQ when switching a key type to a limited server server: https://developers.google.com/maps/faq#switch-key-type

Alternatively, you can continue to use the browser key and the client side based on geocode (JavaScript), and then return the result to the backend via ajax.

+16
source

Source: https://habr.com/ru/post/1264089/


All Articles