Google API Key issues with Google Places

霸气de小男生 提交于 2020-01-06 19:56:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!