I am in the middle of developing an iOS app where there is a request to Google places and the results are displayed. Here is the code for fetching the information:
func fetchPlaceDetails(placeId: String) {
let apiKey = "My Google API KEY"
let urlString = "https://maps.googleapis.com/maps/api/place/details/json?placeid=\(placeId)&key=\(apiKey)"
guard let url = URL(string: urlString) else {
self.errorMessage = "Invalid URL"
return
}
}
I have set placeid somewhere else.
The error I get back from Google is this:
"error_message": "This IP, site or mobile application is not authorized to use this API key. Request received from IP address [IP address], with empty referer" "status": "REQUEST_DENIED"
On the console side I get a (4xx) error.
Things I have tried:
- Making a new API key
- Hardcoding the placeID and the API key into the request
- Using the same API key to display a map in the same app (this worked for the map but not for the places request)
- Restricting the API to just the PlacesAPI
- Unrestricting the key at all
- I have Google Places enabled in the API Key
- I am using package dependencies (8.3.0)
Right now I have the rawJSON data being displayed on the screen. The error above is what is returned. I would like the rawJSON from the request to be displayed.