简体   繁体   中英

How to get more than 3 reviews from Yelp API request

I would like to retrieve reviews for a clinic in New York via the Yelp API. However, the API only seems to only return the first three reviews.

My code

# Finding reviews for a particular clinic
import http.client
import json
import urllib.parse

api_key= 'MY API KEY'

API_HOST = 'https://api.yelp.com/reviews'
SEARCH_PATH = '/v3/businesses/search'
BUSINESS_PATH = '/v3/businesses/'  
# Business ID will come after slash.


headers = {
'Authorization': 'Bearer %s' % api_key,
}

#need the following parameters (type dict) 
params = {'name':'MinuteClinic', 'address1':'241 West 57th St', 'city':'New York', 'state':'NY', 'country':'US'}


param_string = urllib.parse.urlencode(params)
conn = http.client.HTTPSConnection("api.yelp.com")
conn.request("GET", "/v3/businesses/matches/best?"+param_string, headers=headers)

res = conn.getresponse()
data = res.read()
data = json.loads(data.decode("utf-8"))
print(data)


b_id = data['businesses'][0]['id']

r_url = "/v3/businesses/" + b_id + "/reviews"    #review request URL creation based on business ID
conn.request("GET",r_url,headers=headers)
rev_res = conn.getresponse()     #response and read functions needed else error(?)
rev_data = rev_res.read()
yelp_reviews = json.loads(rev_data.decode("utf-8"))


print(yelp_reviews)
print(len(yelp_reviews))

Is there a way to get all the reviews? Thank you so much.

As you may have seen on the Yelp API documentation , there is currently no way to retrieve more than three reviews for a single business with the Business Reviews endpoint ( /businesses/{id}/reviews ) that you are using.

The only accepted parameter for the Business Reviews endpoint is locale .

In addition, the first sentence of the documentation for that endpoint is

This endpoint returns up to three review excerpts for a given business ordered by Yelp's default sort order .

So, at this time, it seems that Yelp only exposes via their API at most three reviews per business. Consider submitting a feature request to the GitHub repository for the Yelp API .

I hate Yelp, I also hate that Google follows suite and also caps the amount of reviews returned. The reviews are public, it's retarded they aren't willing to give programmatic access to get all of them; and they wonder why devs have to create workarounds to bypass these limitations..

Anywho; I created a temp API key for one of my APIs; this one will fetch all the reviews you need from any Yelp profile;

Example call:

http://api.reviewsmaker.com/yelp/?url=https://www.yelp.com/biz/chicha-brooklyn&api_key=4b3d3d92-27f4-4eaa-bb8b-281cb8aa3860

Parameters:

url - full URL of the yelp business page you need to get the reviews for (required) api_key - use the one in the above link, I provisioned it to expire (keep that in mind) rating - you can specify &rating=5 to only pull 5 star reviews, or &rating=2 to only pull 2 star reviews, etc; this is optional, leaving it blank will return all the reviews

Go ahead and grab your clinic's stuff :)

Yelp's Fusion API allows users to search for up to 1000 business listings for a keyword, but when it comes to reviews Yelp is not so generous.

However, getting access to their API is next to impossible. I know many people who applied with no success.

The only remaining option is to scrape the reviews from Yelp. While Yelp may claim that they do not "allow" any scraping of their data, they cannot enforce this as scraping of public data remains legal.

The following technologies can be used to write a crawler for Yelp reviews:

If you don't have time and don't mind spending a few bucks. I have also built a service that scrapes Yelp reviews for you and returns them as an API response for any listing on Yelp.

It is called Yelp Reviews API and can be used to scrape up to 10,000 reviews for free.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM