def get_access_token(self, client_id, client_secret, auth_code):
"""
Aquire an OAuth2 access token
To be run one time (then use refresh token)
"""
# curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&code=THE_GIVEN_CODE" https://www.freesound.org/apiv2/oauth2/access_token/
data = "client_id=%(client_id)s&client_secret=%(client_secret)s&grant_type=authorization_code&code=%(auth_code)s"%locals()
print data
request = urllib2.Request( 'https://www.freesound.org/apiv2/oauth2/access_token/', data=data )
# request.add_header('Accept', 'application/json')
# try:
response = urllib2.urlopen(request)
# except urllib2.HTTPError, exc:
# if exc.code == 401: # Unauthorized
# raise Unauthorized("Bad request")
return json.JSONDecoder().decode(response)
评论列表
文章目录