2016-12-25 73 views
-1

因为在包含Google地图库时发布密钥并不是一个好习惯,所以我从项目中的包含链接中删除了密钥,并将我的站点IP添加到我的API密钥的关键限制列表(我已添加了计费信用卡)。 从那以后,我一直在我的网站上收到'NoApiKeys'警告。在控制台中添加密钥限制后出现'NoApiKeys'错误

我缺少什么? 为什么Google的网站上没有一个简单的例子呢? (所有示例显示将链接添加到链接,但最佳做法页面说,以避免它)

谢谢。

+0

您是否从IP上的端口工作? – 2016-12-25 14:47:06

+0

对于Google Maps JavaScript API v3,密钥必须在网页上公开。最佳做法是将密钥限制为您控制的网址。 – geocodezip

+0

是的,我目前正在从一个港口工作。我暂时删除它,但错误仍然存​​在。 返回链接的密钥根本不会加载地图,给出错误:'RefererNotAllowedMapError' – Daniel

回答

0

对于Google Maps JavaScript API v3,密钥必须公开在网页上。最佳做法是将密钥限制为您控制的网址。

根据谷歌的Best practices for securely using API keys

When you use API keys in your applications, take care to keep them secure. Publicly exposing your credentials can result in your account being compromised, which could lead to unexpected charges on your account. To keep your API keys secure, follow these best practices:

  • Restrict your API keys to be used by only the IP addresses, referrer URLs, and mobile apps that need them: By restricting the IP addresses, referrer URLs, and mobile apps that can use each key, you can reduce the impact of a compromised API key. You can specify the hosts and apps that can use each key from the console by opening the Credentials page and then either creating a new API key with the settings you want, or editing the settings of an API key.
+0

我已经看到这篇文章,并试图实现,但如果我在谷歌控制台中定义关键限制,并包含与加载失败的密钥库。 – Daniel

+0

JavaScript控制台未加载时出现的错误是什么? – geocodezip

+0

我得到的错误是'RefererNotAllowedMapError'。 有没有人知道如何联系谷歌对此事的支持? 我认为改进控制台的syntex并允许定义URL和服务器IP可以真正帮助那些正在使用预生产版本的人 – Daniel

0

解决!

显然,谷歌控制台不是很友善,当试图添加关键限制时给出的例子很糟糕(...和谷歌应该感觉不好)。总结:当添加域名而不是输入* .example.com/**时,请完全键入域名:https://example.com/ *(或任何与您的域对应的版本,因为它是从世界访问的)。

希望这篇文章缩短了某人的痛苦。 干杯。

+0

我不会低估这篇文章,但如果你看到这个,让我知道我做错了什么,如果这不是可以帮助别人的东西。 – Daniel