Key Error: 'groups' (Foursquare API explore venues)

115 views Asked by At

KeyError : 'groups'

When I call results = requests.get(url).json()['response']['groups'][0]['items']

My foursquare API calls are not exhausted yet and still this error shows up every time. I even tried running it by using new client ID and client secret but the problem still persists. I would love to have some strong solution to this issue so that I can progress further with my project.

1

There are 1 answers

0
Todd S. On

It looks like you are parsing the json incorrectly for the latest version of the Places API. 'response', 'groups' and 'items' are not returned.

You can find all the available fields on the Places search response here --> https://developer.foursquare.com/reference/response-fields

I was able to successfully return the first item from a request with the below code. Just replace the API key with yours and it should work.

from os import system
import requests

url = "https://api.foursquare.com/v3/places/search?ll=41.8789%2C-87.6359&&radius=50000"

results = requests.get(url, headers={"Accept":"application/json", "Authorization":"yourApiKey"})

print(results.json()['results'][0])