2016-01-22 60 views
0

我正在一個應用程序,我需要從谷歌地點API查詢地點,並保存到用戶的谷歌帳戶(他們登錄到應用程序通過GIDSignIN)最近的地方。 Places API可在控制檯激活他們的關鍵是正確的,但是,網址可能是有問題的,我不斷收到這個錯誤...谷歌API的關鍵問題谷歌的地方

可選([「ERROR_MESSAGE」:這個IP,網站或移動應用程序不是 授權使用此API密鑰。從IP地址 收到的請求2607:f598:b349:fd01:94f8:7386:d82c:1b29,具有空引用者, 「results」:(),「status」: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() 

} 

任何人都可以提供幫助嗎?謝謝!

回答

2

這種類型的錯誤通常出現在您未在Google控制檯上啓用Api的情況下發生。所以請在控制檯上啓用Api。