Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 862
Charlie Rode Avatar asked Jul 03 '19 00:07

Charlie Rode


People also ask

How do I get Google Geocoding API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.

How do I fix Google Maps platform rejected your request this API project is not authorized to use this API?

Note: The Google Places API Web Service does not work with an Android or iOS restricted API key. So you have to create new key if or remove restricted access of existing key to work it properly. This is the correct answer for the Google reviews FYI.


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}"
like image 104
dcorking Avatar answered Nov 15 '22 07:11

dcorking