Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

After Google started to force developers to use API keys I changed my code accordingly and for a while everything was working fine. It wasn't until I tested my application on a real server that I started to get the 'Browser API keys cannot have referer restrictions when used with this API.' error. It didn't take too long to figure out why this happens and how to fix it so read on to find out.

I was using the Google Maps Time Zone API when this error came up. This is what the JSON response looked like...
 Error Response
{
"errorMessage" : "Browser API keys cannot have referer restrictions when used with this API.",
"status" : "REQUEST_DENIED"
}


Google actually documents this error in their FAQ and also has the statement below on on of their pages...
Important: If you are using any of the web service APIs with a browser key that has referer restictions, your requests will fail with the error message: "Browser API keys cannot have referer restrictions when used with this API." You should switch to using server keys.


So what does it mean? It means that the API key created in the developer console is of a wrong type and has domain access restrictions i.e. you can make requests using that key from particular domains only. In my case I had a 'browser' key with domain access restrictions as below...
gmaps_apikey_err.png

gmaps_apikey_err2.png




The quickest way of resolving this is simply to remove the domain restriction and wait 5 minutes for Google's servers to catch up. This is not ideal or secure since it opens up your key to quota thieves.

Since the API I was accessing is a 'web service' API, it is not meant to be accessed via client side JavaScript. With that in mind a better solution is to create a 'server' key and use that for all future requests. This of course means the requests should be moved out of JavaScript and into the backend system (PHP in my case). That is a more secure solution but will require slight redesign in your application e.g. I will need to create a wrapper around this service and expose it to my JavaScript code.

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Tiny Arcade revision 6 kit assembly and decal application

Jersey JAX-RS filters and interceptors execution order for a simple GET request

How to stop macOS adding shadows to window screenshots

How to run Atari Lynx games on the SNES Classic Mini

Maven dependency scopes with relation to WAR file packaging and the WEB-INF/lib directory

Hacking the Sonoff B1 WiFi LED bulb to run custom firmware

What does an idle WebLogic server run on the hour to cause a CPU spike

How to open the Sonoff B1 wifi LED bulb to access its internal circuitry

Australian release SNES mini classic unboxing and a quick play through

Troubleshooting high CPU usage for JVM threads

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity