Access denied for map geocode api [duplicate] - google-maps

I'm trying to program geocoding. I created API key, but when I add it into my website code I don't get anything, however when I don't use API everything works well. When I'm sending:
https://maps.googleapis.com/maps/api/geocode/json?address=".$adres."&key=KLUCZ_XXX
I get a response:
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 queries is limited per day.
Key constraint: referrals HTTP (Web) - set to the domain from which conjure inquiry. Interface Google Maps Geocoding API is turned on.
Does the API key has to be activated also somewhere else to work?

It sounds like you may be making the API call server side. I ran into this issue earlier today. Since you've placed a referrer restriction on your API key, it will be limited to executing on the browser with the web service APIs, including the Geocoding API. It didn't work for me even when manually setting the referrer in the request headers. You can find the other web service APIs on this page: https://developers.google.com/maps/web-services/
Important: If you are using any of the web service APIs with an API key that has referer restictions, your requests will fail with the error message: "API keys cannot have referer restrictions when used with this API." You should switch to using a server restriction.
You'll want to create a separate key to use server-side. You can change your restriction from a browser restriction to a server restriction by using IP addresses to restrict access, instead of browser referrers.
See this section in the Maps APIs FAQ on switching key type to a server restricted key: https://developers.google.com/maps/faq#switch-key-type
Alternatively, you can continue using a browser key and geocode client-side (JavaScript), then return the result to the backend via ajax.

If server-side geocoding is not an option, you should use the geocoder from the Google Javascript API. You can set HTTP referer restrictions on that API.
Google itself says to avoid the Non-Javascript Geocoder API for dynamic geocoding:
This service is generally designed for geocoding static
(known in advance) addresses for placement of application content on a
map; this service is not designed to respond in real time to user
input. For dynamic geocoding (for example, within a user interface
element), consult the documentation for the Maps JavaScript API client
geocoder and/or the Google Play services Location APIs.

This issue happens when you set the referrer for the server key to the domain name instead of the IP address, then it will show this message -
API keys with referer restrictions cannot be used with this API
.
For geocode API create a separate API key and restrict that API using IP address.
It worked for me.

Related

API key restricted to specific Android app can be used to call maps API with no restriction

I have API key with following configuration:
Application restrictions -> Android apps (with specific package name and certificate fingerprint)
API restrictions -> No restriction
With described configuration, it is possible to successfully call certain maps services with any client (i.e. with no regards to application restriction). For example:
https://maps.googleapis.com/maps/api/streetview?location=41.403609,2.174448&size=456x456&key=YOUR_API_KEY
https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=YOUR_API_KEY
Requests to others maps services are denied as expected. For example:
https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&key=YOUR_API_KEY
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
Do you know of any reason for such inconsistent behavior?
While it is true that setting restrictions to your API key will only allow it to be used by the restriction you had set, however it is an expected behavior for only the Maps Static API and Maps Streetview Static API requests to work even if there are application restrictions applied in an API key due to their particular qualities which made them different from the other APIs. These working requests would be considered as unsigned requests.
However, you can still keep your API key protected by:
Have a dedicated API key to be used only with your Maps Static API requests and sign all your requests with digital signatures (https://developers.google.com/maps/documentation/maps-static/get-api-key#gen-sig);
Once you have your Static Maps API requests working with a digital signature, you can lower your unsigned requests usage. To lower or disable this unsigned request use you can set "Unsigned requests (if URL signing secret is defined) per day" limit to 0 so that requests without a digital signature will not be permitted.
https://cloud.google.com/apis/docs/capping-api-usage#view_and_edit_all_quotas_for_apis_in_a_project
Furthermore, there is an existing Feature Request in the Public Issue Tracker to break referrerless unsigned requests: https://issuetracker.google.com/124860491 You can star the issue if you are interested.

Google Maps API is never satisfied

If I use URL referrer authentication with Geocoding API it says:
There was an error while trying to fix the Venues geolocation information: API keys with referer restrictions cannot be used with this API.
Which after research I find that this means that Google Maps is looking for IP address authentication.
But if I use IP address authentication with Javascript Maps API it says:
JavaScript API error: RefererNotAllowedMapError
https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error
Your site URL to be authorized: https://example.com
What can be going on?
How can I fully satisfy the good ol'Google Maps?
It looks like you're using two different Maps APIs; the client-side JavaScript API and the server-side Geocoding API web service. This means you need 2 API keys; one restricted with HTTP referrers for client-side use, and the other one restricted by IP address for web services only.
To learn more on how API key restrictions work check out Google's documentation on API key best practices.
Hope this helps!
I know this is 3 months old now. But I had the same problem and I found out how to solve this.
As evan said, you need 2 API Keys. And annoyingly, The Events Calendar only have one field for the API Key.
BUT, I found a link here: https://support.theeventscalendar.com/ to https://support.theeventscalendar.com/716190-Using-Google-Maps-API-Key-Restrictions. The page redirects though... But I managed to screen shot parts of it before it redirects and found this snippet: https://gist.github.com/cliffordp/a2ec320313afbc1ffb5f0e5ac654b7fb
(I changed the code to use a define instead because I don't want my API key in git)
This filter will make it possible to have two API KEYS.

Google Static Maps rejects requests for some domains

On some domains Google Maps returns instead of image this error message: The Google Maps Platform server rejected your request. You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account
Domains where it does not work:
http://en.aston-martin-club.com/test_mapa.php
http://en.ktm-club.cz/test_mapa.php
Domains where it works:
http://en.renault-club.cz/test_mapa.php
http://en.lada-club.eu/test_mapa.php
The image I display on web is from http://maps.googleapis.com/maps/api/staticmap URL. It is Google Maps Stati API https://developers.google.com/maps/documentation/maps-static/intro
Why on some domains it works and some not? If it wil not work for any domain, then I think I need to add "key=YOUR_API_KEY" parameter.
I spent many hours trying to find out the reason, but did not succeeded. Any help is very welcome.
In the past (and this is probably still the case), domains that were using the API before keys became required were "grandfathered" with keyless access (they will work without a key).
Keys are now required, so regardless whether the domains "work" without keys or not, it is best to add a valid key to the request.
The things that determine whether or not the domains are "grandfathered" to keyless access are:
When the domain was created
When the domain started using the Google Maps APIs
Google rejects all the requests for static images that does not include api key in URL.
I don't know Google's threshold, but en.aston-martin-club.com is blocked by Google obviously. You must include api key in URL at least.

Google places autocomplete from client-side app

Anyone wise to whether it is possible to use the google places autocomplete api from a client side app.
I tried to access it with a jsonp request to the following url..
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=#{input}&types(regions)&language=en_en&key=MY_API_KEY&callback=JSONP_CALLBACK"
And I get this response
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 94.33.38.138, with referer: http://localhost:3000/"
What I'm finding out is that the autocomplete api requires a server key, and can only be accessed from the backend. Is that correct? Or is there another way to access it from a browser?
I need to combine the results from the places autocomplete with another autocomplete list on the same input field so the google places autocomplete widget is not an option.
You may request the predictions via the autocomplete-service of the places-library of the javascript-API( https://developers.google.com/maps/documentation/javascript/places-autocomplete#place_autocomplete_service )...no key is required and it may be requested from client-side

Where to place API key for Google Geocoding API?

We use Google Geocoding API to map address to Latitude and Longitude.
Here is the sample URL for encoding (which returns json) -
http://maps.googleapis.com/maps/api/geocode/json?address=Dallas&sensor=false
Message: OVER_QUERY_LIMIT
Ok, it makes sense, because we exceed over 2500 daily limit so we place API key like this -
http://maps.googleapis.com/maps/api/geocode/json?key=xxxxx&address=Dallas&sensor=false
Message: REQUEST_DENIED
I'm wondering where/how to place the API Key.
Looks like in version 3 you need to pass the ClientID in the URL and not a key as you do in the free version: https://developers.google.com/maps/articles/v2tov3#newkey
So your URL should look like: http://maps.googleapis.com/maps/api/geocode/json?client=xxxxx&address=Dallas&sensor=false
Not lucky enough to have a paid account so I cannot test - but I think that will get you on the correct path.
Relevant from this link: https://developers.google.com/maps/documentation/business/webservices/
Client ID
You must include your client ID in all API requests. Your client ID
identifies you as a Maps API for Business customer and enables support
and purchased quota for your application. Requests made without a
client ID are not eligible for Maps API for Business benefits.
If you're switching from the free API services to a Maps API for
Business implementation, you must remove the key parameter from your
requests. Google Maps API web services will deny requests made with
both a client ID and a key.
More information is available in the Authentication and Authorization
chapter of this guide.
If you have lost your client ID, you can recover it by logging in to
the support portal and clicking Maps: Add URLs from the links on the
left of the page.
EDIT
For more information, including instructions on passing your client ID to the Earth API, v2 API, and the Maps API for Flash, please read Loading Client-side APIs.
If you have lost your client ID or cryptographic key, you can recover them by logging in to the support portal and clicking Maps: Add URLs from the links on the left of the page.