Created
September 21, 2016 07:27
-
-
Save dawranliou/d0b0c8d434cf5f06f983443f7aaf4985 to your computer and use it in GitHub Desktop.
Example to use Yelp Fusion API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import requests | |
| app_id = os.environ['APP_ID'] | |
| app_secret = os.environ['APP_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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment