问题
I'm working on an app where I need to query places from the google places API and save the nearest place to the user's google account (they sign into the app through GIDSignIN). The Places API is activated in the console and they key is correct, however, the URL might be problematic and I keep getting this error...
Optional(["error_message": This IP, site or mobile application is not authorized to use this API key. Request received from IP address 2607:f598:b349:fd01:94f8:7386:d82c:1b29, with empty referer, "results": ( ), "status": REQUEST_DENIED, "html_attributions": ( )])
The method that is called to query the API, the current lat and on long come from the location manager (working fine)
func saveCurrentLocation() {
//API CALL
let latString = String(currentLat)
let longString = String(currentLong)
let apiString = NSString(format: "https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=500&types=food&sensor=true&key=AIzaSyDH0jNx1WJw0pkCzbc0xaHumDoDAYYWvtk", latString, longString)
let url = NSURL(string: apiString as String)
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithURL(url!) { (data, response, error) -> Void in
if let urlContent = data {
do {
let jsonDictionary = try NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.AllowFragments) as? [String:AnyObject]
print(jsonDictionary)
}
catch {
print("JSON error")
}
}
}
dataTask.resume()
}
Anyone able to help? Thanks!
回答1:
This type of error usually comes when you not enable your Api on Google console. So please make your Api enable on Console.
来源:https://stackoverflow.com/questions/34955629/google-api-key-issues-with-google-places