Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Places Api iOS Daily Limit for Unauthenticated Use Exceeded error

I am trying to use google places api for iOS. I created an api key and then I am trying to call a few methods. I have entered the api key in the app but when I make the call I get an this error

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

Domain=com.google.GTLJSONRPCErrorDomain Code=403 "(Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.)" UserInfo={error=Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup., NSLocalizedFailureReason=(Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.), GTLStructuredError=GMSx_GTLErrorObject 0x7f8bf2be6060: {message:"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." data:[1] code:403}}}}

I provide the api key in my appdelegate using GMSServices.provideAPIKey("MY_API_KEY") and I 've given location access to the app. I certainly haven't exceed my usage limits (my quota shows 0 out of 1000) since I haven't been able to talk with the api. I 've regenerated the key some times and I also have created other keys with other gmail accounts but nothing worked...

My guess is either something is not right with the ios simulator location (I ve provided a gpx file to pass a custom location) or something is wrong from google's side.

The two samples that I have in my code are:

                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)")
                }
            })

and

                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 is a var instantiated as GMSPlacesClient(). Am I missing something here? The rest of the code is a typical Xcode single application project.

like image 352
Michael Kornelakis Avatar asked Jul 15 '16 13:07

Michael Kornelakis


1 Answers

Answering my own question here!

Turns out the mistake was totally mine (as it usually is). I was setting the placesClient var like this

var placesClient = GMSPlacesClient()

In google's example (check it here) the placesClient var is declared as an optional GMSPlacesClient and then in viewDidLoad is set to GMSPlacesClient.sharedClient(). Unfortunately I missed that part. The code is like

var placesClient: GMSPlacesClient?

override func viewDidLoad() {
    super.viewDidLoad()
    placesClient = GMSPlacesClient.sharedClient()
}
like image 52
Michael Kornelakis Avatar answered Nov 15 '22 18:11

Michael Kornelakis