【发布时间】:2016-01-22 20:44:02
【问题描述】:
我正在开发一个应用程序,我需要从 google 地方 API 查询地点并将最近的地点保存到用户的 google 帐户(他们通过 GIDSignIN 登录应用程序)。 Places API 在控制台中激活,并且它们的密钥是正确的,但是,URL 可能有问题,我不断收到此错误...
Optional(["error_message": 此IP、站点或移动应用程序不是 授权使用此 API 密钥。从 IP 地址收到的请求 2607:f598:b349:fd01:94f8:7386:d82c:1b29,引用为空, “结果”:(),“状态”:REQUEST_DENIED,“html_attributions”:()])
用于查询 API 的方法,当前纬度和经度来自位置管理器(工作正常)
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()
}
有人可以帮忙吗?谢谢!
【问题讨论】:
-
我启用了places api,然后我也遇到了同样的错误,你是如何克服的,请你发布解决方案@Echizzle
标签: ios swift google-places-api nsjsonserialization