def request(host, path, bearer_token, params):
"""Given a bearer token, send a GET request to the API.
Args:
host (str): The domain host of the API.
path (str): The path of the API after the domain.
bearer_token (str): OAuth bearer token, obtained using client_id and client_secret.
params (dict): An optional set of query parameters in the request.
Returns:
dict: The JSON response from the request.
Raises:
HTTPError: An error occurs from the HTTP request.
"""
url = '{0}{1}?{2}'.format(
host,
quote(path.encode('utf8')),
urllib.urlencode(params))
headers = {
'Authorization': 'Bearer %s' % bearer_token,
}
logging.info(u'Querying {0} ...'.format(url))
result = urlfetch.fetch(
url=url,
method=urlfetch.GET,
headers=headers)
logging.info('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' + result.content)
return json.loads(result.content)
评论列表
文章目录