zadrozny
zadrozny

Reputation: 1731

API not working for Javascript or REST, producing KeyError

I'm trying to replicate the Reverse Geocoding section in this article: https://developer.here.com/blog/getting-started-with-geocoding-exif-image-metadata-in-python3

I've tried with creds for both Javascript and Rest. For the Javascript creds, I've copy-pasted the app_id. For app_code I'm using the "API KEY". For the REST creds, I've tried pairing the app_id with both the "API KEY" and the "ACCESS KEY ID".

Both produce a `KeyError: 'xxxxxxxxxxxxxxxx'

Upvotes: 1

Views: 121

Answers (1)

Michel
Michel

Reputation: 28349

There is a bit of trickiness involved, due to the fact that app_id and app_code pair have been deprecated in favor of apiKey. The blog post was written before that change.

So if you created your HERE project recently and have an api key instead of an app_id and app_code pair, you need to:

  1. Replace app_id and app_code parameters with apiKey instead, with the value accordingly
  2. Check and adjust the endpoint url (.api.here.com became .ls.hereapi.com)

See below:

#uri = 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json'
uri = 'https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json'
headers = {}
params = {
    #'app_id': os.environ['APP_ID_HERE'],
    #'app_code': os.environ['APP_CODE_HERE'],
    'apiKey': os.environ['API_KEY_HERE'],
    'prox': "%s,%s" % coords,
    'gen': 9,
    'mode': 'retrieveAddresses',
    'maxresults': 1,
}

See also the documentation examples for reverse geocode

Upvotes: 1

Related Questions