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

1

6

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.

Jeremiad answered 3/7, 2019 at 0:38 Comment(3)
Check your request again something is wrong its not picking up your key. Check for spaces in your request parms you could also try putting key first but it shouldnt matter i suspect something needs to be encoded in your addressChangchun
Please note that this would require further assistance from the Google Maps Platform support team, kindly file a support case via console.cloud.google.com/google/maps-apis/support in order to open personalized communication channel.Chaulmoogra
Make sure you are correctly encoding your URL and/or try generating a new key.Phineas
G
6

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}"
Gid answered 23/7, 2019 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.