質問

Yelpのレストラン情報を収集しようとしています。私はレストランの名前を持っていて、Yelpapiを使っています。

次のように入力しました:

from yelpapi import YelpAPI
yelp_api = YelpAPI(<key>, <secret>, <token>, <token secret>)
search_results = yelp_api.search_query(name = 'Neptune Oyster', location='Boston, MA'),
.

しかし、20社のリストで終わった、どれも正しいものはありませんでした。私のAPIクエリにレストラン名を指定するにはどうすればいいですか?

また、特定のレストランのすべてのレビューを引き出すことについてどのようにして行くのでしょうか。

ありがとう!

役に立ちましたか?

解決

あなたが探しているレストランはあなたが探しているレストランです:

http://www.yelp.com/biz/neptune-oyster-boston?
.

最後の '/'後のすべてのものはレストランのYelp-IDです。

YELP-IDを使用したら、ビジネスAPIを使用してレビューを取得する必要があります

これはビジネスAPI

のドキュメントです。
http://www.yelp.com/developers/documentation/v2/business
.

レビューを得るためのあなたの要求は次のようになります:

http://api.yelp.com/v2/business/neptune-oyster-boston
.

そして特にPython Yelpapiのために、要求は

として構成することができます
yelp_api.business_api('neptune-oyster-boston')
.

それは私にレビューの狙撃を与えました、フルレビューのために、あなたがウェブサイトを掻き集める必要があるかもしれないと思います。美しいサッピとスクエアを見てください。

最後に、あなたの最初の質問に答えるために、nameを検索パラメータのtermに置き換えてください。このページに他の有効な検索パラメータのリストがあります。

http://www.yelp.com/developers/documentation/v2/search_api
.

次のクエリで、APIは私に正しいビジネスを与えました。

yelp_api.search_query(term='neptune oysters', location='boston', limit=1)
.

頑張って幸せな掻き取り!

他のヒント

新しいYelp Fusion API(v3)には、APIの使用方法と情報が返されるかに対するいくつかの変更が発生しました。それの短いは、単一の通話でレビューを得ることができます。V3には2つの呼び出しが必要です。以下は私がそれを働かせることができた方法です。あなたの走行距離はさまざまです。

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

headers = {
'authorization': "Bearer <access_token>",
'cache-control': "no-cache",
'postman-token': "<token>"
}
#need the following parameters (type dict) to perform business search. 
params = {'name':'Neptune oyster', 'address1':'63 Salem St.', 'city':'Boston', 'state':'MA', '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"))

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(json.dumps(yelp_reviews, indent=3, separators=(',', ': ')))
.

Specifying the restaurant name using term instead of name seems to work.

from yelpapi import YelpAPI
yelp_api = YelpAPI(key, secret, token, token_secret)
search_results = yelp_api.search_query(term='Neptune Oyster', location='Boston, MA')

>>> for business in search_results['businesses']:
...     print business['name']
... 
Neptune Oyster
Island Creek Oyster Bar
B & G Oysters
Rabia's
Union Oyster House
Pauli's
James Hook & Co
Row 34
Atlantic Fish Company
Mare
The Oceanaire Seafood Room
Alive & Kicking Lobsters
The Daily Catch
Yankee Lobster Fish Market
The Barking Crab
Boston Chowda Co.
Legal Sea Foods
Salty Dog Seafood Grille & Bar
Legal Sea Foods
Legal Sea Foods

According to the documentation, you are limited to 1 excerpt of a review. You can get that using a business query with the id of the business that you got from the search query:

>>> search_results = yelp_api.search_query(limit=1, term='Neptune Oyster', location='Boston, MA')
>>> if search_results['businesses'][0]['name'] == 'Neptune Oyster':
...     business_id = search_results['businesses'][0]['id']
...     business_results = yelp_api.business_query(id=business_id)
...     for review in business_results['reviews']:
...         print review['excerpt']
... 
Price/Food
- Waited almost two hours for this place! I talked to some people that were waiting in line and they were all raving that Neptune is the BEST...
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top