def authenticated_get(
url, customer_key=CUSTOMER_KEY, customer_secret=CUSTOMER_SECRET):
"""Performs an authenticated GET to the given URL, returns the response's
content.
See https://dev.twitter.com/oauth/application-only
"""
token = get_access_token()
response = urlfetch.fetch(
url,
method=urlfetch.GET,
headers={'Authorization': 'Bearer ' + token})
if response.status_code == urlfetch.httplib.OK:
return response.content
elif response.status_code == urlfetch.httplib.UNAUTHORIZED:
return response.content # User is probably suspended
else:
message = 'Url ' + url + ' returned ' + response.content
logging.warning(message)
raise urlfetch.httplib.HTTPException(message)
评论列表
文章目录