4
votes

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

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.

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

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

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?

2
Hi. It could be &amp; Did you tried to replace it with & ?Janis Lankovskis
@JanisLankovskis - Thanks, but it's still using &amp; and working. The new call is simply: //maps.googleapis.com/maps/api/js?libraries=places&amp;sensor=false&amp;key=APPLICATIONKEYdazbradbury

2 Answers

14
votes

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

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

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

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".

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

javascriptUrlsToIgnore="maps.googleapis.com"

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

3
votes

The Google Maps JavaScript API recently advanced a minor version increment to 3.9changelog and the default version advanced from 3.6 to 3.7. I notice that you aren't specifying a version in the URL you use to load the Google Maps JavaScript API library, so you retrieve the default version, 3.7. One important thing about version 3.7 is that it now requires the use of keys for some libraries. Info about which version you should use is available in the Versioning section of the Developer's Guide.

A few others have run into similar problems, but if you are running fine after adding the key, you should be good. If you would like to receive notifications about Google Maps API changes in the future, you may register for notifications.