javascript Google Maps V3 API 密钥无效 - 但我的个人开发密钥有效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15281897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Maps V3 API Key Invalid - but my personal dev key works
提问by Corey Snyder
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/*
我最近一直在开发将我们的地图升级到 v3,并且在开发过程中我使用了我自己的个人密钥。一切正常。当需要投入生产时,我让某人通过公司的 google 帐户生成了一个密钥,但现在它不起作用了。我坐在他们旁边确保他们正在生成浏览器密钥,并且我很确定“Referrer's”部分下的域是正确的: .mydomain.com/mydomain.com /*
I've verified that we are using Key for browser apps.
我已经确认我们正在将 Key 用于浏览器应用程序。
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.
我已经通过服务面板验证了 Google Maps API v3 已打开。一切都与我使用钥匙的方式相同。我认为唯一的区别是他们在公司帐户上启用了帐单,而我的密钥没有。我们希望将其从我的关键中移开,因为它如何接收超过我帐户每天 25,000 次观看次数限制。
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"
使用公司 API 密钥时,地图会加载,然后很快我收到一个警告框,上面写着:“Google 已禁用此应用程序的 Maps API。提供的密钥不是有效的 Google API 密钥,或者未经授权用于此站点上的 Google Maps Javascript API v3。如果您是此应用程序的所有者,您可以在此处了解如何获取有效密钥: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.
任何帮助将不胜感激。
采纳答案by Corey Snyder
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.
我能够通过简单地生成一个新的浏览器密钥来解决这个问题。我生成,把它扔到浏览器中,加载了地图。然后我进入并从上一个键复制了我的推荐人。已保存。焕然一新。它仍然有效。老实说,我认为这是 Google 的一个错误,在我们生成原始密钥的那天,它吐出无效密钥。
回答by Mark
You are missing the v=3
before your key={yourkey}
你错过了v=3
之前的key={yourkey}
Like this:
像这样:
maps.googleapis.com/maps/api/js?v=3&key={your key}&sensor=false
回答by Aero Wang
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.
实际上,您希望Google Maps JavaScript API
启用而不是Google Maps API v3
因为前者是您在此处实际使用的。后者现在分为iOS和Android BTW。
Also you need to add your reference into your server key.
您还需要将您的参考添加到您的服务器密钥中。
If it is local, it should be something like:
如果它是本地的,它应该是这样的:
localhost/*
localhost/*
回答by FrVaBe
I think you must check the referrers. The given example on the API console site is:
我认为你必须检查推荐人。API 控制台站点上的给定示例是:
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 thispost. You can find a description of the possible whitelist configuration on the Google APIs Console Help page.
尝试在不使用通配符的情况下包含完整的引荐来源名称。通配符的用法似乎有点奇怪。更多的人为此而苦苦挣扎,请参阅这篇文章。您可以在Google API 控制台帮助页面上找到可能的白名单配置的说明。
(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.)
(您提到您的个人密钥与您的公司密钥具有相同的引用。我想知道这是否可行,因为在这种情况下您可以为同一个应用程序使用不同的密钥。)
回答by Alex Levine
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">
<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
^ 那个?v=3.exp
有点
回答by Dan2552
Under referrers, we had *
. The fix was actually to leave it blank `` which means allow all.
在推荐人下,我们有*
. 修复实际上是将其留空`` 这意味着允许所有。
回答by Yaseen Khan
Add v=3;
before your key.
v=3;
在您的密钥之前添加。
maps.googleapis.com/maps/api/js?**v=3;**key={your key};sensor=false
回答by aequalsb
I had a number of reports from clients about problems with Google maps on their sites. I checked and got "Invalid key" errors.
我从客户那里收到了许多关于他们网站上 Google 地图问题的报告。我检查并收到“无效密钥”错误。
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.
奇怪的是,Google 过去常常在 API 密钥之前和之后给出带有空格的密钥。过去,当我离开空格时,钥匙坏了。记住离开这些空间是令人沮丧的。
Now, I trim()
my current API Key (with or without spaces) before submitting it to Google Maps and it works.
现在,在将trim()
我当前的 API 密钥(带或不带空格)提交到 Google 地图之前,它可以工作。
回答by Roman Bondar
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.
现在从谷歌添加地图变得比以前更成问题。在https://leafletjs.com/页面上,您会发现另一个更方便的带地图的图书馆。
回答by Eric Leroy
If you are testing locally, make sure to add your local ip to the server key:
如果您在本地测试,请确保将您的本地 ip 添加到服务器密钥:
xxx.xxx.xxx.xxx
if you want the maps api to be available across the whole domain add this to the browser key:
如果您希望地图 API 在整个域中可用,请将其添加到浏览器键中:
*.mydomain.com/*
Hope this helps.
希望这可以帮助。