Google Maps JavaScript API RefererNotAllowedMapError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35288250/
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 JavaScript API RefererNotAllowedMapError
提问by Grupo Camaleón Creativos
We're trying to develop an geoplacement app for one of our clients, and we want first to test it in out own domain.
我们正在尝试为我们的一个客户开发一个地理定位应用程序,我们希望首先在自己的域中对其进行测试。
We have signed for Google Maps JavaScript API, and we have a valid browser key and our domain, www.grupocamaleon.com, has been authorized to use that key.
我们已经签署了 Google Maps JavaScript API,我们有一个有效的浏览器密钥,我们的域 www.grupocamaleon.com 已被授权使用该密钥。
But we can't make even the easiest example to run without error.
但是我们不能让最简单的例子运行没有错误。
We have, in our domain and with our key, the following demo:
我们在我们的域和我们的密钥中有以下演示:
(1) http://www.grupocamaleon.com/boceto/aerial-simple.html
(1) http://www.grupocamaleon.com/boceto/aerial-simple.html
But it doesn't work, and Firebug console says:
但它不起作用,Firebug 控制台说:
"Google Maps API error: Google Maps API error: RefererNotAllowedMapError (link to Google documentation on RefererNotAllowedMapError) Your site URL to be authorized: (1)"
“Google Maps API 错误:Google Maps API 错误:RefererNotAllowedMapError(链接到有关 RefererNotAllowedMapError 的 Google 文档)您要授权的站点 URL:(1)”
My credential page is missing the possibility of adding referrers to accept, so solutions involving adding referrers are not possible right now.
我的凭据页面缺少添加推荐人以接受的可能性,因此目前无法解决涉及添加推荐人的解决方案。
My credential Page:
我的凭证页面:
Why do we get that error? How can we fix it?
为什么我们会得到这个错误?我们该如何解决?
回答by powerbuoy
I know this is an old question that already has several answers, but I had this same problem and for me the issue was that I followed the example provided on console.developers.google.com and entered my domains in the format *.domain.tld/*
. This didn't work at all, and I tried adding all kinds of variations to this like domain.tld
, domain.tld/*
, *.domain.tld
etc.
我知道这是一个已经有几个答案的老问题,但我遇到了同样的问题,对我来说问题是我遵循了 console.developers.google.com 上提供的示例并以*.domain.tld/*
. 这并没有在所有的工作,我尝试添加各种变化,这个像domain.tld
,domain.tld/*
,*.domain.tld
等等。
What solved it for me was adding the actual protocoltoo; http://domain.tld/*
is the only one I need for it to work on my site. I guess I'll need to add https://domain.tld/*
if I were to switch to HTTPS.
为我解决的是添加实际的协议;http://domain.tld/*
是我需要它在我的网站上工作的唯一一个。https://domain.tld/*
如果我要切换到 HTTPS,我想我需要添加。
Update: Google have finally updated the placeholder to include http
now:
更新:谷歌终于更新了占位符,http
现在包括:
回答by Rick James
Come on Google, you guys are smarter than the API Credential page lets on. (I know because I have two sons working there.)
来吧 Google,你们比 API Credential 页面更聪明。(我知道,因为我有两个儿子在那里工作。)
The list of "referrers" is far pickier than it lets on. (Of course, it shouldbe more forgiving.) Here are some rules that took me hoursto discover:
“推荐人”列表比它允许的要挑剔得多。(当然,它应该更宽容。)以下是我花了几个小时才发现的一些规则:
- The order in the list is important. Moving your URL up in the list may make it work.
- "http://" prefix is required.
- Even "localhost" needs it: "http://localhost/foo/bar.html"
- A trailing
*
as a wildcard seems to work as if it is a string compare. - Even with "http://localhost/foo/bar.html", "http://localhost/foo/bar.html?arg=1" will not work. (Will a wildcard help?)
- For both prod dev, have (at least) two rows: "http://localhost/foo/bar.html" and "http://my.site.com/foo/bar.html"
- A port number (8085? 4000?) does not seem to be necessary.
- 列表中的顺序很重要。在列表中向上移动您的 URL 可能会使其工作。
- “http://”前缀是必需的。
- 甚至“localhost”也需要它:“ http://localhost/foo/bar.html”
- 作为通配符的尾随
*
似乎是一个字符串比较。 - 即使使用“ http://localhost/foo/bar.html”,“ http://localhost/foo/bar.html?arg=1”也不起作用。(通配符会有帮助吗?)
- 对于两个 prod dev,有(至少)两行:“ http://localhost/foo/bar.html”和“ http://my.site.com/foo/bar.html”
- 端口号(8085?4000?)似乎不是必需的。
There are probably other rules, but this is a tedious guessing game.
可能还有其他规则,但这是一个乏味的猜谜游戏。
回答by TRose
According to the documentation, 'RefererNotAllowedMapError' means
根据文档,“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 the Google Developers Console.
加载 Google Maps JavaScript API 的当前 URL 尚未添加到允许的引用者列表中。请在 Google Developers Console 上检查您的 API 密钥的引用设置。
I have the Google Maps Embed API set up for my own personal/work use and thus far have not specified any HTTP referrers. I register no errors. Your settings must be making Google think the URL you're visiting is not registered or allowed.
我为自己的个人/工作使用设置了 Google Maps Embed API,到目前为止还没有指定任何 HTTP 引用。我没有注册错误。您的设置必须让 Google 认为您访问的网址未注册或未获允许。
回答by ow3n
I tried many referrer variations and waiting 5 minutes as well until I realized the example Google populates in the form field is flawed. They show:
我尝试了许多引荐来源变体并等待了 5 分钟,直到我意识到 Google 在表单字段中填充的示例存在缺陷。他们展示:
*.example.com/*
However that only works if you have subdomain.
or www.
in front of your domain name. The following worked for me immediately (omitting the leading period from Google's example):
但是,这仅在您拥有subdomain.
或www.
位于您的域名之前才有效。以下内容立即对我有用(从 Google 的示例中省略了领先时期):
*example.com/*
回答by Putu De
Just remind that if you just change it, it may take up to 5 minutes for settings to take effect.
请注意,如果您只是更改它,则设置可能需要长达 5 分钟才能生效。
回答by RIYAJ KHAN
According the google docsthis happened because the url
on which you are using the Google Maps API, it not registered
in list of allowed referrers
根据谷歌文档,这是因为url
您使用的是谷歌地图 API,它not registered
在list of allowed referrers
EDIT :
编辑 :
From Google Docs
All subdomains of a specified domain are also authorized.
If http://example.comis authorized, then http://www.example.comis also authorized. The reverse is not true: if http://www.example.comis authorized, http://example.comis not necessarily authorized
指定域的所有子域也被授权。
如果http://example.com被授权,那么http://www.example.com也被授权。反之则不然:如果http://www.example.com被授权,则http://example.com不一定被授权
So,Please configure http://testdomain.com
domain, then your http://www.testdomain.com
will start work.
所以,请配置http://testdomain.com
域,然后您http://www.testdomain.com
将开始工作。
回答by David Robertson
Check you have the correct APIS enabled as well.
检查您是否也启用了正确的 API。
I tried all of the above, asterisks, domain tlds, forward slashes, backslashes and everything, even in the end only entering one url as a last hope.
我尝试了上述所有方法,星号、域 tlds、正斜杠、反斜杠和所有内容,甚至最后只输入一个 url 作为最后的希望。
All of this did not work and finally I realised that Google also requires that you specify now which API's you want to use (see screenshot)
所有这些都不起作用,最后我意识到谷歌还要求您现在指定要使用的 API(见截图)
I did not have ones I needed enabled (for me that was Maps JavaScript API)
我没有需要启用的(对我来说是 Maps JavaScript API)
Once I enabled it, all worked fine using:
启用它后,使用以下方法一切正常:
I hope that helps someone! :)
我希望能帮助别人!:)
回答by hiroshi
I found that even your HTTP Referreres
are valid enough, wrong set of API Restrictions
causes Google Maps JavaScript API error: RefererNotAllowedMapError
.
我发现即使你HTTP Referreres
的API Restrictions
理由也足够有效,错误的原因集Google Maps JavaScript API error: RefererNotAllowedMapError
。
For example:
例如:
- You are using Javascript API for the key.
- Add
http://localhost/*
toApplication Restrictions / HTTP Referrences
- Choose
Maps Embed API
instead ofMaps Javascript API
- This causes
RefererNotAllowedMapError
- 您正在使用 Javascript API 作为密钥。
- 添加
http://localhost/*
到Application Restrictions / HTTP Referrences
- 选择
Maps Embed API
而不是Maps Javascript API
- 这引起
RefererNotAllowedMapError
回答by Daniel Loureiro
Wildcards (asterisks) ARE NOTallowed in the subdomain part.
通配符(星号)都没有在子域部分允许的。
- WRONG:*.example.com/*
- RIGHT:example.com/*
- 错误:*.example.com/*
- 右图:example.com/*
Forget what Google says on the placeholder, it is not allowed.
忘记谷歌在占位符上所说的,这是不允许的。
回答by dakab
There are lots of supposed solutions accross several years, and some don't work any longer and some never did, thus my up-to-date take working per end of July 2018.
几年来有很多假设的解决方案,有些不再有效,有些从未有效,因此我在 2018 年 7 月下旬进行了最新的工作。
Setup:
设置:
Google Maps JavaScript API has to work properly with…
Google Maps JavaScript API 必须与…
- multiple domains calling the API:
example.com
andexample.net
- arbitrary subdomains:
user22656.example.com
, etc. - both secure and standard HTTP protocols:
http://www.example.com/
andhttps://example.net/
- indefinite path structure (i.e. a large number of different URL paths)
- 调用 API 的多个域:
example.com
和example.net
- 任意子域:
user22656.example.com
等 - 安全和标准的 HTTP 协议:
http://www.example.com/
和https://example.net/
- 不定路径结构(即大量不同的 URL 路径)
Solution:
解决方案:
- Actually using the pattern from the placeholder:
<https (or) http>://*.example.com/*
. - Not omitting the protocol, but adding two entries per domain (one per protocol).
- An additional entry for subdomains (with a
*.
leading the hostname). - I had the feeling that the
RefererNotAllowedMapError
error still appeared using the proper configuration (and having waited ample time). I deleted the credential key, repeated the request (now gettingInvalidKeyMapError
), created new credentials (using the exact same setup), and it worked ever since. - Adding mere protocol and domain seemed not to have included subdomains.
- For one of the domains, the working configuration looks like this:
- 实际上使用占位符中的模式:
<https (or) http>://*.example.com/*
. - 不省略协议,而是为每个域添加两个条目(每个协议一个)。
- 子域的附加条目(以
*.
主机名开头)。 - 我有一种感觉,
RefererNotAllowedMapError
使用正确的配置(并等待了足够的时间)仍然会出现错误。我删除了凭证密钥,重复了请求(现在得到了InvalidKeyMapError
),创建了新的凭证(使用完全相同的设置),从那时起它就开始工作了。 - 添加仅仅协议和域似乎没有包含子域。
- 对于域之一,工作配置如下所示:
(As text:)
(如文字:)
Accept requests from these HTTP referrers (web sites)
https://*.example.com/*
https://example.com/*
http://*.example.com/*
http://example.com/*