Google Geocoding API request with cURL denied. I have an API key associated to a project with billing enabled

Viewed 3302

I'm attempting to access Google's Geocoding API with the following:

curl https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=XXX

I get back the following:

{"error_message": You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account", "results": [], "status": "REQUEST_DENIED"}

They key I'm passing is associated to a project with both the Geocoding and Places APIs enabled, and the project has billing enabled as well.

1 Answers

I think the shell is interfering with some characters in your query. If you use bash or a similar shell, it works for me to surround the query address with single quotes or double quotes. For example:

curl 'https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=XXX'
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
...

For more convenience, you can store the key in a shell environment variable, and use double quotes for the shell to expand it in your query. Here is what I do:

export GOOGLE_MAPS_API_KEY=XXX
curl "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=${GOOGLE_MAPS_API_KEY}"
Related