[英]How to gather data about venues' ratings using Foursquare API
I need help with my homework. 我的作业需要帮助。 I want to get the ratings of a specific number of venues using Foursquare API.
我想使用Foursquare API获得特定数量场所的评级。
Tis is what I came up with so far 这是我到目前为止想出的
venues_ids= df['id']
ratings=[]
for venue_id in venues_ids.values.tolist():
url = 'https://api.foursquare.com/v2/venues/{}?client_id={}&client_secret={}&v={}'.format(venue_id, CLIENT_ID, CLIENT_SECRET, VERSION)
result = requests.get(url).json()
try:
venues_rating=result['response']['venues']['rating']
ratings=ratings+[venues_rating]
except IndexError:
print('No data available for id=',ID)
ratings
I'm expecting a list with all the ratings for the specific ids. 我期待一个包含所有特定ID评级的列表。 However, I get the error message---- KeyError: 'venues'
但是,我收到了错误消息---- KeyError:“ venues”
Any tip would be appreciated! 任何提示将不胜感激! Thank you!
谢谢!
Try 尝试
venues_rating=result['response']['venue']['rating'] // not 'venues'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.