I want to use the textSearch (=%7B%22fields%22%3A%22*%22%2C%22resource%22%3A%7B%22textQuery%22%3A%22Spicy%20Vegetarian%20Food%20in%20Sydney%2C%20Australia%22%7D%7D) in Places API (New) to obtain all of the POIs of one specific category in an area, but I'm always getting no return from the code.
My code:
import requests
def get_places_by_category(query, api_key):
# Base URL for the Text Search API
base_url = ":searchText"
# Parameters for the request
params = {
"query": query,
"key": api_key
}
# Send the request
response = requests.get(base_url, params=params)
# Check if the request was successful
if response.status_code == 200:
return response.json()
else:
return None
# Example usage
api_key = API_KEY # Replace with the actual API key
query = "restaurant" # Category of POIs you want to search for
places = get_places_by_category(query, api_key)
if places:
for place in places['results']:
print(f"Name: {place['name']}, Address: {place['formatted_address']}")
else:
print("Failed to get a response from Google Places API (New)")
It keeps returning "Failed to get a response from Google Places API (New)".