ios_google_places_autocomplete icon indicating copy to clipboard operation
ios_google_places_autocomplete copied to clipboard

Getting Error :- GooglePlaces API Error: REQUEST_DENIED

Open aanchalkalani opened this issue 8 years ago • 4 comments

Hi,

While searching any thing getting error :- GooglePlaces API Error: REQUEST_DENIED

We added our API key properly and follow the below :-

Manual Simply copy GooglePlacesAutocomplete.swift and GooglePlacesAutocomplete.xib to your project. Note: Don't forget to add the PoweredByGoogle image to your xcassets.

Thanks,

aanchalkalani avatar Aug 23 '16 07:08 aanchalkalani

@watsonbox , In swift 3 and ios 10 I am also getting the same error. Previously it used to work fine

RanjitKadam avatar Oct 16 '16 07:10 RanjitKadam

The same problem for me.

Gladkov-Art avatar Oct 18 '16 10:10 Gladkov-Art

It seems that I have tracked down the problem. It was related to escaping of optional query parameters. Here is the solution (I have rewritten the origin functions):

  fileprivate class func query(_ parameters: [String: AnyObject]) -> String {
    var components: [(String, String)] = []
    for key in Array(parameters.keys).sorted(by: <) {
        if let value = parameters[key] as? String {
            let escapedValue = escape(value)
            components += [(escape(key), escapedValue)]
        }
    }
    return (components.map{"\($0)=\($1)"} as [String]).joined(separator: "&")
  }

  fileprivate class func escape(_ string: String) -> String {
    var escapedCharacters = CharacterSet.urlQueryAllowed
    escapedCharacters.remove(charactersIn: ":/?&=;+!@#$()',*")
    return string.addingPercentEncoding(withAllowedCharacters: escapedCharacters) ?? ""
  }

Gladkov-Art avatar Oct 19 '16 04:10 Gladkov-Art

fileprivate class func query(_ parameters: [String: AnyObject]) -> String {
        var components: [(String, String)] = []
        for key in Array(parameters.keys).sorted(by: <) {
            let value: AnyObject = parameters[key]!
            components += [(escape(key), escape("\(value)"))]
        }
        
        return (components.map{"\($0)=\($1)"} as [String]).joined(separator: "&")
    }


Or like this works too

4taras4 avatar May 11 '17 00:05 4taras4