Javascript 不允许使用 Google 地图 API 引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32600314/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 13:56:22  来源:igfitidea点击:

Google maps API referrer not allowed

javascriptgoogle-maps

提问by bwash70

I am getting the error RefererNotAllowedMapErrorfrom some PC's when I load a page on my site.

RefererNotAllowedMapError当我在我的网站上加载页面时,我从某些 PC 上收到错误消息。

RefererNotAllowedMapError

The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key on Google Cloud Console.

See API keys

RefererNotAllowedMapError

加载 Google Maps JavaScript API 的当前 URL 尚未添加到允许的引用者列表中。请在 Google Cloud Console 上检查您的 API 密钥的引用设置。

查看 API 密钥

It works OK on FireFox from 3 out of four of the machines I have tested.

在我测试过的四台机器中的三台上,它在 FireFox 上运行正常。

Generally this would mean that the domain is not added as a referer in my API console but it definitely is, and it definitely works on other machines.

通常,这意味着该域不会作为引用添加到我的 API 控制台中,但确实如此,并且它肯定可以在其他机器上运行。

Anyone else had this issue or able to provide some guidence?

其他人有这个问题或能够提供一些指导?

回答by bwash70

Recreating the API key at console.developers.google.comfixed the issue for me.

console.developers.google.com 重新创建API 密钥为我解决了这个问题。

回答by Bunty

Try to add all type of urls like:

尝试添加所有类型的网址,例如:

http://stackoverflow.com/*

http://www.stackoverflow.com/*

*.stackoverflow.com/*

Definitely it will work.

肯定会奏效的。

回答by jean d'arme

For me to use Places APII had to turn on Maps JavaScript API

为了我使用,Places API我必须打开Maps JavaScript API

回答by Mir3

I had a similar issue where I was trying to use the API but had it restricted to Map product only. It generated the same error even though http referrer box had nothing in it (open for all). The problem went away after recreating a new key without any product restriction.

我在尝试使用 API 时遇到了类似的问题,但它仅限于 Map 产品。即使 http 引荐来源框中没有任何内容(对所有人开放),它也会产生相同的错误。在没有任何产品限制的情况下重新创建新密钥后,问题就消失了。

回答by R.evolvan

This gives error because your Google map API key is not a browser key. Create new key as 'browser key'. This option is available when you create a new key.

这会导致错误,因为您的 Google 地图 API 密钥不是浏览器密钥。创建新密钥作为“浏览器密钥”。创建新密钥时,此选项可用。

回答by DevWL

Note the DOTat the beginning of the expression, it's a char!

注意表达式开头的DOT,它是一个字符!

*.stackoverflow.com/*// this will not work with http://stackoverflow.com

*.stackoverflow.com/*// 这不适用于 http://stackoverflow.com

You will also have to add:

您还必须添加:

*://stackoverflow.com/*// now it will cover all domain variation

*://stackoverflow.com/*// 现在它将涵盖所有域变化

回答by Sarat Chandra

Creating an new Browser Key fixed it for me. https://console.developers.google.com/projectselector/apis/credentials

创建一个新的浏览器密钥为我修复了它。 https://console.developers.google.com/projectselector/apis/credentials

RefererNotAllowedMapError Error The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key on the Google API Console.

See API keys in the Google API Console. For more information, see Best practices for securely using API keys.

RefererNotAllowedMapError 错误 加载 Google Maps JavaScript API 的当前 URL 尚未添加到允许的引用者列表中。请在 Google API 控制台上检查您的 API 密钥的引用设置。

请参阅 Google API 控制台中的 API 密钥。有关更多信息,请参阅安全使用 API 密钥的最佳实践。

回答by Dr. C. Hilarius

The only thing that worked for me was to create a brand new key w/no restrictions, including no API restrictions.

唯一对我有用的是创建一个没有限制的全新密钥,包括没有 API 限制。

This won't be a working solution in the production environment, but it allows us to move ahead w/development.

这在生产环境中不是一个可行的解决方案,但它允许我们继续开发。

回答by Tahir77667

The solution to every/such Maps Javascript APIerror varies for different scenarios for different developers. A list of errors with detailed description is given by google here

Maps Javascript API对于不同的开发人员,每个/此类错误的解决方案因不同的场景而异。谷歌在这里给出了带有详细描述的错误列表

Nevertheless please refer the below snap: Maps Javascript API restrictions

不过请参考以下快照: 地图 Javascript API 限制

  1. As you can see above under Application restrictionsjust by selecting the HTTP referrers won't do. You have to add a URL(i.e the URL of the website from which the api will be called to render the map).
  2. Now the exact page(in my case the contact us page) which is gonna make the request to the api needs to be mentioned in the url and not just the domain.
  3. Please go through the examples given in the documentation on the right
  4. Adding a /*after the domain url like http://www.telesuprecon.com/*will make the request possible from any page within your website.
  1. 正如您在上面的应用程序限制下所看到的,仅通过选择 HTTP 引荐来源是行不通的。您必须添加一个 URL(即将调用 api 以呈现地图的网站的 URL)。
  2. 现在,需要在 url 中提及向 api 发出请求的确切页面(在我的情况下是联系我们页面),而不仅仅是域。
  3. 请仔细阅读右侧文档中给出的示例
  4. /*在域 url 之后添加一个likehttp://www.telesuprecon.com/*将使您网站中的任何页面的请求成为可能。