Corey Snyder
Corey Snyder

Reputation: 236

Google Maps V3 API Key Invalid - but my personal dev key works

I've recently been doing development upgrading our maps to v3 and during development I was using my own personal key. Everything was working fine. When it was time to go to production I had someone generate a key through the company's google account and now it doesn't work. I've sat next to them making sure they were generating a browser key, and I'm pretty sure the domains are correct under the "Referrer's" section matching both: .mydomain.com/ mydomain.com/*

I've verified that we are using Key for browser apps.

I've verified that the Google Maps API v3 is turned ON via the services panel. Everything is identical to the way I was doing it with my key. I think the only difference is that they've enabled Billing on the company account where as my key doesn't. We'd like to get this moved off of my key seeing as how it's receiving more than the 25k views/day limit on my account.

When using the company API key the map loads and then very quickly I get an alert box which reads: "Google has disabled use of the Maps API for this application. The provided key is not a valid Google API Key, or it is not authorized for the Google Maps Javascript API v3 on this site. If you are the owner of this application, you can learn about obtaining a valid key here: https://developers.google.com/maps/documentation/javascript/tutorial#api_key"

If I then replace the key with my own key, with the same referrers settings, it works..

Any help would be greatly appreciated.

Upvotes: 11

Views: 47484

Answers (11)

Roman Bondar
Roman Bondar

Reputation: 103

Now adding a map from Google has become more problematic than it was before. On the page https://leafletjs.com/ you will find another more convenient library with maps.

Upvotes: 0

aequalsb
aequalsb

Reputation: 4055

I had a number of reports from clients about problems with Google maps on their sites. I checked and got "Invalid key" errors.

Strangely, Google used to give out keys with a space before and after the API key. In the past, when I left the spaces off, the key broke. It was frustrating to remember to leave those spaces.

Now, I trim() my current API Key (with or without spaces) before submitting it to Google Maps and it works.

Upvotes: 2

Yaseen Khan
Yaseen Khan

Reputation: 21

Add v=3; before your key.

maps.googleapis.com/maps/api/js?**v=3;**key={your key};sensor=false

Upvotes: 2

Aero Wang
Aero Wang

Reputation: 9267

Actually you want the Google Maps JavaScript API to be enabled instead of Google Maps API v3 because the former is what you are actually using here. The latter is now divided into iOS and Android BTW.

Also you need to add your reference into your server key.

If it is local, it should be something like:

localhost/*

Upvotes: 5

Dan2552
Dan2552

Reputation: 1264

Under referrers, we had *. The fix was actually to leave it blank `` which means allow all.

Upvotes: 2

Alex Levine
Alex Levine

Reputation: 1597

I hit my head against the wall on this for a while. Including the version number, which the example does not do, fixed it for me.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=YOURKEY">

^ That one has the ?v=3.exp bit

Upvotes: 3

Tim Dawson
Tim Dawson

Reputation: 89

I have been getting the invalid key message too, and after trawling all round the web, have found what MY problem was. It may affect others too. It had nothing to do with the key.

I discovered that I had an error in the 'initialize' function (in my case a missing comma at the end of a line in the mapOptions). This arose because I added a new (last) line, and failed to put a comma at the end of the preceding one. A good argument for always having a comma, even on the last line.

I can now switch the invalid key message ON or OFF my removing/replacing that comma. I conclude that any error in the map related JS may give rise to it.

Upvotes: 0

Eric Leroy
Eric Leroy

Reputation: 1836

If you are testing locally, make sure to add your local ip to the server key:

xxx.xxx.xxx.xxx

if you want the maps api to be available across the whole domain add this to the browser key:

*.mydomain.com/*

Hope this helps.

Upvotes: 0

Mark
Mark

Reputation: 229

You are missing the v=3 before your key={yourkey}

Like this:

maps.googleapis.com/maps/api/js?v=3&key={your key}&sensor=false

Upvotes: 22

Corey Snyder
Corey Snyder

Reputation: 236

I was able to resolve this issue by simply generating a new browser key. I generated, threw it in the browser, the map loaded. Then I went in and copied my referrers over from the previous key. Saved. Refreshed. And it still worked. I honestly think it was a bug on Google's end and the day we were generating the original keys it was spitting out invalid keys.

Upvotes: 10

FrVaBe
FrVaBe

Reputation: 49351

I think you must check the referrers. The given example on the API console site is:

Example: *.example.com/*. *One URL or pattern per line.*

Try to include the full referrer names without using wildcards. The wildcard usage seems a bit strange. More people struggle with that, see this post. You can find a description of the possible whitelist configuration on the Google APIs Console Help page.

(You mentioned that your personal key has the same referrers as your company key. I wonder if this is possible as you could use different keys for the same app in this case.)

Upvotes: 4

Related Questions