【问题标题】:Yelp API Validation_Error when making post request发出发布请求时出现 Yelp API Validation_Error
【发布时间】:2017-03-07 00:59:53
【问题描述】:

我正在尝试从 Yelp API 获取访问令牌,并已阅读开发人员页面的说明以及请求文档,当我尝试发出请求时,它返回 {"error": {"code": "VALIDATION_ERROR", "description": "/oauth2/token/"}}我查找错误Yelp 开发者页面上的代码,但没有找到此错误代码。

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)

有人可以帮我看看有什么问题吗?提前致谢。

【问题讨论】:

    标签: python api yelp


    【解决方案1】:

    请看下面的代码。这是绝对正确且有效的示例代码。

    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'])
    

    【讨论】:

      猜你喜欢
      • 2012-11-19
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 2015-10-07
      • 2018-05-18
      • 2017-08-06
      • 2017-04-30
      • 2019-01-23
      相关资源
      最近更新 更多