def refresh_token(self, client_id, client_secret, refresh_token):
"""
To get a new access token using your refresh token you basically need to repeat Step 3 setting the grant_type parameter to ‘refresh_token’ (instead of ‘authorization_code’) and adding a refresh_token parameter with your refresh token (instead of adding the code parameter with the authorization code). See the following example:
# curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN" "https://www.freesound.org/apiv2/oauth2/access_token/"
"""
data = "client_id=%(client_id)s&client_secret=%(client_secret)s&grant_type=refresh_token&refresh_token=%(refresh_token)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")
print(response)
return json.JSONDecoder().decode(response)
评论列表
文章目录