2016-12-25 71 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