Reputation: 351
I'm trying to get an access token from the Yelp API and have read the instructions from the developers page as well as the documentation for requests and when I try to make the request, it returns {"error": {"code": "VALIDATION_ERROR", "description": "/oauth2/token/"}}
I looked up error codes on the Yelp developer page but didn't find this error code.
import json
from pip._vendor import requests
clientID= 'my id as a string'
clientSecret ='my secret as a string'
par = {'grant_type' : 'client_credentials', 'client_id':clientID,'client_secret':clientSecret}
content = requests.post('https://api.yelp.com/oauth2/token/',params=par)
print(content.text)
Can someone please help me see what's wrong? Thanks in advance.
Upvotes: 0
Views: 657
Reputation: 1109
Please see below code. It is absolutely correct and working example code.
import requests
app_id = 'client_id'
app_secret = 'client_secret'
data = {'grant_type': 'client_credentials',
'client_id': app_id,
'client_secret': app_secret}
token = requests.post('https://api.yelp.com/oauth2/token', data=data)
access_token = token.json()['access_token']
url = 'https://api.yelp.com/v3/businesses/search'
headers = {'Authorization': 'bearer %s' % access_token}
params = {'location': 'San Bruno',
'term': 'Japanese Restaurant',
'pricing_filter': '1, 2',
'sort_by': 'rating'
}
resp = requests.get(url=url, params=params, headers=headers)
import pprint
pprint.pprint(resp.json()['businesses'])
Upvotes: 2