2016-07-15 115 views
6

我想爲iOS使用谷歌地方api。我創建了一個API key,然後我試着調用一些方法。我已經進入了應用程序的API密鑰,但是當我打這個電話,我得到了這個錯誤Google Places Api iOS每日限制未經驗證的使用超出的錯誤

lookup place id query error: The operation couldn’t be completed. (com.google.places.server.ErrorDomain error -1.) 
Error Domain=com.google.places.server.ErrorDomain Code=-1 "(null)" UserInfo={NSUnderlyingError=0x7f8bf861ca80 {Error 

域= com.google.GTLJSONRPCErrorDomain代碼= 403「(爲 未經驗證的日常使用超出限制。續使用需要註冊。)「 UserInfo = {錯誤=未經驗證的使用超過每日限制。 繼續使用,需要註冊,NSLocalizedFailureReason =(對未驗證的日常使用限制 超出續使用需要註冊。), GTLStructuredError = GMSx_GTLErrorObject 0x7f8bf2be6060:{消息:「每日 限制對未驗證的使用超出繼續使用要求 註冊」數據:[1]的代碼:403}}}}

我提供在我的appdelegate使用GMSServices.provideAPIKey( 「MY_API_KEY」)的API密鑰和我已經到應用程序給定的位置的訪問。我當然沒有超過我的使用限制(我的配額顯示爲0的1000),因爲我沒有能夠與API交談。我已經重新生成密鑰有時,我也創建了與其他Gmail帳戶的其他密鑰,但沒有任何工作...

我的猜測是不是正確的與ios模擬器的位置(我提供了一個gpx文件通過一個自定義位置)或谷歌的一面是錯誤的。

兩個樣品,我有我的代碼是:

   let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs" 

      placesClient.lookUpPlaceID(placeID, callback: { (place: GMSPlace?, error: NSError?) -> Void in 
       if let error = error { 
        print("lookup place id query error: \(error.localizedDescription)") 
        print(error) 
        return 
       } 

       if let place = place { 
        print("Place name \(place.name)") 
        print("Place address \(place.formattedAddress)") 
        print("Place placeID \(place.placeID)") 
        print("Place attributions \(place.attributions)") 
       } else { 
        print("No place details for \(placeID)") 
       } 
      }) 

   placesClient.currentPlaceWithCallback({ (placeLikelihoods, error) -> Void in 
       guard error == nil else { 
        print("Current Place error: \(error!.localizedDescription)") 
        return 
       } 

       if let placeLikelihoods = placeLikelihoods { 
        for likelihood in placeLikelihoods.likelihoods { 
         let place = likelihood.place 
         print("Current Place name \(place.name) at likelihood \(likelihood.likelihood)") 
         print("Current Place address \(place.formattedAddress)") 
         print("Current Place attributions \(place.attributions)") 
         print("Current PlaceID \(place.placeID)") 
        } 
       } 
      }) 

placesClient是()實例化爲GMSPlacesClient一個變種。 我在這裏錯過了什麼嗎? 其餘代碼是一個典型的Xcode單一應用程序項目。

+1

它說「超出未經驗證的使用的每日限制」。這將表明您實際上未登錄。這意味着每個IP地址的每日限制適用,而不是您的配額。 – fishinear

+0

你能否提供更多細節?我必須在哪裏登錄?我創建了我的應用程序並獲得了我的API密鑰。然後我在我的代碼中使用該鍵與api連接。我應該登錄哪一點? –

回答

17

在這裏回答我自己的問題!

原來的錯誤完全是我的(正如通常那樣)。我設置了placesClient VAR這樣

var placesClient = GMSPlacesClient() 

在谷歌的例子(check it here)的placesClient VAR聲明爲可選GMSPlacesClient,然後在viewDidLoad中被設置爲GMSPlacesClient.sharedClient()。不幸的是我錯過了那部分。該代碼就像

var placesClient: GMSPlacesClient? 

override func viewDidLoad() { 
    super.viewDidLoad() 
    placesClient = GMSPlacesClient.sharedClient() 
} 
+0

其工作,謝謝 – Alexi

相關問題