Provided key is not a valid Google API key - google-maps

I am new to google map api. I copied the Hello_World.html from google maps javascript v3 getting started. But I always get the error message: the provided key is not a valid google api key.
I tried a few things but none of them worked. The following is what I did:
I edited the allowed referrers to mysite.com/* and localhost/*. But the error message is still there.
I tried a method someone suggested, which adds javascript version number:
change src="https://maps.googleapis.com/maps/api/js?key={XXX....X}&sensor=true" to src="https://maps.googleapis.com/maps/api/js?v=3.6key={XXX....X}&sensor=true", even so, the error message is still there.
Can someone give me any suggestions?

You do not need a key for Google Maps API v3, see the documentation. Your API v2 key will not work.
You will only need key for API v3 in case you want some additional features (very high traffic site, additional statistics etc.). But this is a very rare case.

You don't need a key, it should work without it. If you provided the key you are using (it isn't secret and can't be used on domains that you don't allow), we could tell if it is at least the correct format.
This
src="https://maps.googleapis.com/maps/api/js?v=3.6key={XXX....X}&sensor=true
is incorrect.
it is missing an & between the v=3.6 and "key".
version 3.6 is no longer available, that will result in the "frozen version", currently version 3.11.

I had this problem. The solution is:
Go to https://code.google.com/apis/console -> api access
Click "Key for browser apps".
The example says to enter *.example.com/* but it doesn't work for me. I had to enter (one per line):
example.com
*.example.com
*.example.com/*
example.com/*
Hope this helps

Related

Detect invalid Google Maps API key format without calling API

I maintain some plugins that allow developers to use the Google Maps javascript API. It is the developer's responsibility to supply their API Key when they build apps using my plugins.
In my sample code and applications where the key must be entered, I put in examples like "(enter your API key here)" or "API_KEY" because these are checked into the publicly accessible source code repository. At the moment, my plugin simply passes this string to the Google Maps API "as is". The only validation I do is to test that some value has been entered.
I want a simple test that will (with reasonable accuracy) determine whether a given string is NOT a real Google Maps API key. So far I haven't seen any documentation from Google indicating what to expect the string to look like.
I don't care if my test sometimes gets false positives, because the developer will get a Google Map error at runtime if they don't have a valid key. I do care about false negatives, however; if they supply a valid Google Maps API key, but my code falsely blocks it as "invalid", that would be a failure on my part.
All the valid Google Maps API keys I've seen seem to be exactly 39 characters long, consisting of the characters AI followed by 37 alphanumeric characters or dashes, e.g.:
AIjlSyEI1n03b7-this-is-fake-5tHcDxy1RnI
Would I run the risk of penalising anyone if I simply tested that the candidate key is at least 39 characters long?
What if I tested that the first two characters are AI?
What if I checked for the existence of characters like (, ), or _?
(if you have seen a valid Google Maps API key that does not conform to the above "rules" I've made up, could you comment? That would help to invalidate my hypothesis.)
(as MrUpsidown pointed out, the documentation does not state any rules one way or another - so the only perfect method would be to call the API - but in my case I want code that will run in isolation on the server side)
You should not rely on string validation because the way API keys are formatted could always change and like you said, it would give a bad customer experience to display an error message for a valid API key. This is a potentially useful feature to get though so I recommend you file a feature request in Google's issue tracker. For now all you can do is call the API to catch any errors should the request fail like MrUpsidown suggested.
Hope this helps!

Suddenly got error message Maps API deactivation and Maps API exceeded quota but everything is normal in the API console

I suddenly got some random message saying "Google has deactivate Maps API" and "Site has exceed daily quota". Image attached (in Indonesian language).
In the console API the quota status is still green. This started three days ago. What would cause this?
I am using Google Maps API for Javascript version 3.17.
It looks like it's a bug with Google: Intermittent Google maps api Authorization Error
https://code.google.com/p/gmaps-api-issues/issues/detail?id=7464
Other possible answers:
I'm seeing other people with the same problem. It looks like Google gives that error message even then the actual problem is something else.
You can get this error if you don't actually enable the version of Google Maps that you're using: http://www.raymondcamden.com/2013/2/13/Getting-a-quote-error-with-Google-and-youve-barely-touched-your-limit
You may have already checked that since you've been in the console to check your usage but including it just in case.
Not having referrers set up properly will also cause it:
https://wordpress.org/support/topic/google-has-disabled-use-of-maps-api-for-this-application
Google maps api v3 reporting key error
People have also found that taking the key out for a while seems to help (though it is unclear why): Different errors (quota, disabled, bad API key, or none) when loading Google Maps API JavaScript
(Scroll to the bottom of the page for the answer)
I also started getting these errors unexpectedly, even though I was a long way from my quota.
I think maybe the browser was making too many requests for the API key for each load, or something.
So, I changed the "requests per user" setting from 1 to 2 per second, and the errors went away.

What is the need for API key?

The tutorial for Google maps API states that an API key is required for making calls to the API. The example given on the page however does not use an API key. So why would'nt someone choose to make the call without an API key and not worry about exceeding any limits?
Thanks,
Yash
Since version 3 you the API key is not mandatory anymore. You still can provide one though to track your usage because the limit still exists. See also this answer.

Access Denied when attempting to use Google Maps Geocoding Service with a Console API Key

UPDATE: In an effort to give a more clear question. How do I use the Google Console API key with the Google Maps Geocoding Web Service API? At the moment the request comes back as denied, when I specify the key but even though it failed it is logged in the Google Console API site's reports section.
Original Question
I have an existing app that has been modified to start geocoding address at the time they are entered (for use within the app on a Google Map). The volume expected for this is expcted to be within the free offering's limites and does not require a key at this time. However now I have to geocode all of the existing addresses. I have a small windows app (C#) that will loop through them one at a time, request they be geocoded (via https://maps.googleapis.com/maps/api/geocode/json) and store the results in the database. However I keep running into the query limit. To help alleviate this I've setup an account on Google API Console (https://code.google.com/apis/console/) so that I get go over the limit and just be billed for the overages.
The problem is in order to do utilize this billing alternative I have to provide a Console API Key to the request, but every time I do so I get a response back with a status of REQUEST_DENIED.
My URL looks like this
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&sensor=false&key=123abc
If I take off the key it works fine, but with it on it fails. Now, I have seen other questions similar to this when looking around but can find no answer to the issue.
I've tried various alternate domains including maps.google.com, maps.googleapis.com and maps-api-ssl.google.com all seem to have the same problem from what I can tell.
Here's what I've been able to find out so far:
The service is listed in the Google Console API's site as Google Maps API v3, (there is a separate entry for v2) so I don't think it's a problem with keys no longer being mandatory in v3.
I know the requests are getting through and being correctly logged against this API key because with each failed attempt the request count goes up by one on the Reports tab of the Google APIs Console.
*I know it's not a problem with it not being accessed via a web page because the Console API explicitly lets you generates keys intended for Server/Service use and you can restrict access to them via IP address, not URL Referrer.
*I've also verified the parameter syntax as it's outlined on this page, as are other usage
*These seem to be generic to the Console API system but there is no mention of exceptions to these practices when used for the Google Maps API.
I even tried to contact Google but apparently they don't offer support over the phone (I was hoping to be done with this today but that's not looking likely).
It seems the key is not necessary anymore, since it doesn't increase your limit of free geocodings.
It was a legacy of v2, but geocoding API v2 was fully deprecated last March, 8.
If you need to use more than the free limit, I think you must adquire the Enterprise license.
Regards,
Eduardo.
I ran into this same issue and solved it by enabling the Geocoding API on the Google apis dashboard. Even though I'm using the Google Maps JavaScript API v3, it still required me to enable the Geocoding API as well. Make sure you understand the google's quota limits and billing system before enabling any API access. Hope this helps!
Late to this answer, but just in case anyone else has issue. Billing needs to be setup first and like Dylan said you also have to enable Geocoding API(this got me). At least I did for my locations app that shows multiple store location addresses.

How to find nearest point of interest using Google Maps API?

For an application I'm developing, I need to find the nearest bus stops using the Google Maps API. How would I accomplish this?
The place search API just returns REQUEST_DENIED, so that isn't much help.
https://maps.googleapis.com/maps/api/place/search/json?key=AIzaSyCNutXaoPSvdgAboAp7CYLZ2S5oVv_Fe7o&location=52.069858,4.291111&radius=1000&sensor=false
http://puu.sh/zUUa
I suspect that REQUEST_DENIED gives you a clue that your query is well-formed, but there is something invalid. If it's not the lack of the sensor parameter, it must be the key you provided. I don't have a key myself to test it, and Google refuses to give it saying the URL I provided is invalid... I can only suggest you to double-check your key, and maybe try with another account.
EDIT: Now I've managed to get my key and found your mistake: you forgot to put https, not http, in your request.