Google Maps V3 API Key Invalid - but my personal d

2020-02-26 07:40发布

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.

11条回答
Root(大扎)
2楼-- · 2020-02-26 07:57

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.

查看更多
聊天终结者
3楼-- · 2020-02-26 08:00

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.

查看更多
家丑人穷心不美
4楼-- · 2020-02-26 08:01

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.)

查看更多
Deceive 欺骗
5楼-- · 2020-02-26 08:06

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

查看更多
乱世女痞
6楼-- · 2020-02-26 08:10

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.

查看更多
Explosion°爆炸
7楼-- · 2020-02-26 08:12

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

查看更多
登录 后发表回答