Igor's Blog

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

, , , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

Migrating domain email from GoDaddy to Google G Suite

NeoOffice Viewer macOS Word Document viewer vs Preview and Microsoft Word

Importance of cleaning the internal fans and heatsinks in a MacBook Pro

Adding an email subscribe feature to your Blog with Blogtrottr

How to remove Google's logo from your G Suite applications

Pedestal fan transformed into a ceiling fan

Testing the Velvet WiFi Hotshot signal strength

Improving slow download speeds on the PS4 and PSN

Add batch image resize functionality to macOS using Automator

Show transfer percentage and speed when copying files in Linux and Bash

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me on...