So many threads on this question, but none could solve my issue. I am trying to download the name and coordinates of a certain point of interest by using the Google Place API and the Python code on my laptop in Spyder. I have created a project, enabled all relevant APIs such as Places API, Geocoding API, Maps JavaScript API, Geolocation API, Maps Enbed API. I also checked the API restrictions and there is none.
I have also created a billing account under that project and linked them.
import googlemaps
import time
gmaps = googlemaps.Client(key= '....') # I replace ... with my Key
coordinates = []
query = "Post Office, Sydney"
try:
response = gmaps.places(query=query)
if response["status"] == "OK": # Check if the request was successful
places = response.get("results", [])
for place in places:
try:
location = place["geometry"]["location"]
lat, lng = location["lat"], location["lng"]
place_details = gmaps.place(place_id=place["place_id"])
types = place_details.get("result", {}).get("types", []) # Get place types
# Ensure there are at least three types
place_type1 = types[0] if len(types) > 0 else "N/A"
place_type2 = types[1] if len(types) > 1 else "N/A"
place_type3 = types[2] if len(types) > 2 else "N/A"
coordinates.append([place["name"], place_type1, place_type2, place_type3, lat, lng]) # Added name of office
time.sleep(0.5) # Reduced this as each call to place() costs
except Exception as e:
print(f"Error processing place: {e}")
else:
print(f"Error: API request failed with status {response['status']}") # Added error message
print(response) # Print the full response for debugging
except Exception as e:
print(f"Error making API request: {e}")
# Print the coordinates (for testing)
for coord in coordinates:
print(coord)
This is the error:
Error making API request: REQUEST_DENIED (This API project is not authorized to use this API.)
As others have already said, you need to activate the legacy Places API.
You seem to have done so, great.
But now you need to also edit your API key API restrictions
and add the Places API
in addition to the Places API (New)
you have already added.
I hope this helps!