I had been using Chromium and wondered why it kept returning error code 403 and the message that’s in the title of this post when using the html5 geolocation features. It turns out that Chromium does not ship with Google’s API credentials as the normal build of Google Chrome does so those services are unavailable (Chrome/Chromium does not use the operating system’s built in location services and instead relies on Google’s API). After reviewing the Chromium documentation here, I’ve come up with the following steps to properly enable Chromium’s google services. It’s a lot of work, but I hope this is useful for the many people using Google’s open source Chromium on Linux, OS X, or Windows.
- Join the chromium dev group here by subscribing. You don’t have to receive email updates, you just have to be a member of the group in order for the right APIs to show up in the developer console.
- Visit the Google API Console and create a new project.
- Visit your project’s page in the console, click the APIs link in the left menu, and begin subscribing to developer APIs of your choice. In order to resolve network location provider issues when using Chromium, you’ll need the “Google Maps Geolocation API”. The Chromium documentation notes the following as useful APIs for Chromium:
- Chrome Remote Desktop API
- Chrome Spelling API
- Chrome Suggest API
- Chrome Sync API
- Chrome Translate Element
- Google Maps Geolocation API – (requires enabling billing but is free to use; you can skip this one, in which case geolocation features of Chrome will not work)
- Safe Browsing API
- Speech API
- Time Zone API
- Google Cloud Messaging for Chrome
- Drive API (Optional, enable this for Files.app on Chrome OS and SyncFileSystem API)
- Google Now For Chrome API (Optional, enabled to show Google Now cards)
- Click the settings gear after enabling the APIs of your choice and choose “Project Billing Settings”.
- Click “Enable Billing”, choose a personal billing account, and enter your billing information. Yes, in order for Google Maps Geolocation API calls to work, you have to have a payment method on your account. Having a payment method tied to your account won’t affect the fact that the quota for API calls to the Geolocation API is 100 calls per day and 100 calls are billed at $0.0 for personal accounts. If you’re still worried, check out Google’s documentation on Geolocation pricing here.
- Click the “Credentials” link in the left menu under “APIs & auth” on the Google API Console.
- Click “create new key”, then click “server key”, then click “create”. This is your “GOOGLE_API_KEY” which you’ll need later.
- Under “OAuth”, click “Create new Client ID”, choose “Installed application” and click “Configure consent screen”. Fill in the required information in the form and click “save”.
- Choose “Installed application” again, and click “Create ClientID”. Now you have your
GOOGLE_DEFAULT_CLIENT_SECRETwhich you’ll need later.
Now you’ll need to setup some environment variables for Chromium to pick up when it’s launched, the rest of these instructions are specifically for OS X using launchd, though with a little bit of googling it should not be that difficult for you to find a solution that works with your OS’ service/startup/daemon manager:
- Create a new script in your home directory, mine is named ‘.setGoogleEnvVars.sh’
- Add the following to the script, replacing the XXXs with appropriate values from your Google API developer console:
launchctl setenv GOOGLE_API_KEY XXX launchctl setenv GOOGLE_DEFAULT_CLIENT_ID XXX launchctl setenv GOOGLE_DEFAULT_CLIENT_SECRET XXX
- Create a new launchd service in your home’s LaunchAgents directory, ~/Library/LaunchAgents/, mine is called
local.setGoogleEnvVars.plistwith the following contents, replacing the label and program argument of “~/.setGoogleEnvVars.sh” if necessary:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>local.setGoogleEnvVars</string> <key>ProgramArguments</key> <array> <string>sh</string> <string>-c</string> <string>~/.setGoogleEnvVars.sh</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
- Make sure your startup script is executable by using the terminal and
chmod +xto set the executable bit like this, replacing the script name if necessary:
chmod +x ~/.setGoogleEnvVars.sh
- At this point, you can either restart your computer or load the service with
launchctl load ~/Library/LaunchAgents/local.setGoogleEnvVars.plist, replacing the plist name if necessary.
That’s it! It’s a lot of work, but you’ve now enabled any of your selected Google APIs in Chromium, and you should no longer receive error messages like
network location provider at 'https://www.googleapis.com/' : returned error code 403. code 2 if you’ve chosen to enable the Geolocation API and billing.