经过几个月的 100% 稳定性,今天我在谷歌地图服务上收到 403 错误 [英] After months of 100% stability, today I get 403 Error on google maps services

查看:30
本文介绍了经过几个月的 100% 稳定性,今天我在谷歌地图服务上收到 403 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有人可以解释为什么我的 google 地图服务会出现 403 Forbidden 错误.

I was just wondering if someone could shed some light on why I am seeing 403 Forbidden errors for my google maps services.

我一直在加载地图 API:

I had been loading the maps api as such:

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?libraries=places&amp;sensor=false"></script>

然后使用地理编码和自动完成库将用户搜索转换为坐标以显示在我搜索结果的地图上.

And then using both the geocoding and autocomplete libraries to turn user searches into co-ordinates to display on a map on my search results.

直到昨天,当我开始看到 403 错误时,每当访问自动完成服务时,这一切都很好(几个月).

This was working perfectly (for months) until yesterday, when I started seeing 403 Errors whenever the Autocomplete service was accessed.

我 100% 确信我没有达到每天 25k 的查询限制,而且我没有对代码进行任何更改.

I am 100% confident I wasn't reaching the 25k per day limit on queries, and I made no code changes on my side.

我现在已经在我的脚本加载中添加了一个 API 密钥,问题消失了,但我想确保这种情况不会再次发生.基于位置的搜索是我们网站的主要功能,如果它中断,我们就会失去客户.

I have now added in an API key to my script load, and the problem dissapeared, but I want to be sure this doesn't happen again. Location based search is a main feature on our site, and if it breaks, we lose customers.

有没有人知道为什么会发生这种情况?

Does anyone have any insight as to why this may have happened?

在什么情况下会再次发生?

And under what circumstances can it happen again?

推荐答案

这个问题刚刚重新出现即使设置了 API 密钥 - 我认为问题实际上在于缓存 google maps javascript.

This problem just re-emerged even with an API key set - and I think the issue actually lies with caching the google maps javascript.

我让我的 Web 服务器动态决定要在本地组合、缩小和缓存哪些 javascript.这是使用 RequestReduce 完成的.

I have my web server dynamically decide what javascript to combine, minify and cache locally. This is done using RequestReduce.

当客户端 javascript 变得陈旧时(在我的情况下大约 3 天) - 谷歌返回 403 未经授权.

When the client-side javascript becomes stale (roughly 3 days in my case) - google returns 403 unauthorized.

API 密钥只是一个红鲱鱼.我可以删除密钥并且我的代码仍然有效 - 只要地图 js 是新鲜的".

The API key was just a red herring. I can remove the key and my code still works - as long as the maps js is "fresh".

就我而言,修复方法是将 maps.googleapis.com 添加到 RequestReduce 忽略列表:

In my case, the fix was to add maps.googleapis.com to the RequestReduce ignore list:

javascriptUrlsToIgnore="maps.googleapis.com"

对于其他人,请确保不要将 maps.googleapis.com javascript 缓存超过几个小时(如果有的话).

For others, just make sure to not cache the maps.googleapis.com javascript for more than a few hours, if at all.

这篇关于经过几个月的 100% 稳定性,今天我在谷歌地图服务上收到 403 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆