Fixing Google Places API Authorization Issue for Location Suggestions
Introduction
Recently, I was working on integrating Google Places API to fetch location suggestions. My goal was to get location autocomplete results based on user input. Initially, I used the following API endpoint:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=New%20York&key=YOUR_GOOGLE_MAPS_API_KEYHowever, when I tried making a request, I encountered the following error:
{
"error_message" : "This API project is not authorized to use this API.",
"predictions" : [],
"status" : "REQUEST_DENIED"
}Debugging the Issue
I went through the Google Maps API documentation to understand why my request was being denied. Here are some possible reasons that can cause this error:
- Incorrect API Key Permissions: The API key may not have the necessary permissions enabled.
- Billing Not Enabled: Google Places API requires a valid billing account linked to the project.
- Using Deprecated API Versions: Google has transitioned to new versions for some services, requiring updated API endpoints.
- Incorrect API Key Usage: Some APIs require specific headers and a different request format.
Finding the Solution
After going through the documentation, I found an alternative API endpoint that provides location suggestions using the Google Places API:
New API Endpoint
https://places.googleapis.com/v1/places:searchTextGet Yash Tiwari’s stories in your inbox
Join Medium for free to get updates from this writer.
Request Method
This API requires a POST request with a JSON body.
Request Body
{
"textQuery" : "Delhi"
}Headers
Content-Type : application/json
X-Goog-Api-Key : your_api_key
X-Goog-FieldMask : places.displayName,places.formattedAddress,places.locationWhy This Works?
- The new endpoint is part of Google’s updated API structure.
- It requires specific headers (
X-Goog-Api-KeyandX-Goog-FieldMask). X-Goog-FieldMaskensures that only necessary fields are retrieved, reducing data usage.- It provides more flexible search functionality with better results.
Final Thoughts
If you’re facing similar issues with the Google Places API, try using the new searchText endpoint instead of autocomplete. Also, ensure that:
- Your API key has the correct permissions enabled.
- You have an active billing account.
- You use the correct headers and request format.
I hope this article helps others struggling with Google Places API authorization errors. Let me know your thoughts or if you have any other suggestions in the comments!
What do you think?
Have you encountered similar issues with Google Maps APIs? Do you have any better alternatives or solutions? Let’s discuss in the comments below!



