Google地方信息中的Google API密钥问题 [英] Google API Key issues with Google Places

查看:82
本文介绍了Google地方信息中的Google API密钥问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序需要从google place API查询位置并将最近的位置保存到用户的google帐户(它们通过GIDSignIN登录到该应用程序).在控制台中激活了Places API,并且它们的密钥正确,但是,URL可能有问题,并且我不断收到此错误...

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...

可选(["error_message":此IP,站点或移动应用程序不是授权使用此API密钥.来自IP地址的请求2607:f598:b349:fd01:94f8:7386:d82c:1b29,带有空引用,结果":(),状态":REQUEST_DENIED,"html_attributions":()])

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": ( )])

用于查询API的方法,当前的经纬度以及长期以来都来自位置管理器(工作正常)

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()

}

有人能帮忙吗?谢谢!

推荐答案

这种错误通常是在您未在Google控制台上启用Api时发生的.因此,请在控制台上启用Api.

This type of error usually comes when you not enable your Api on Google console. So please make your Api enable on Console.

这篇关于Google地方信息中的Google API密钥问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆