I want to get refresh token from Dailymotion API by this code
def get_refresh_token(code):
platform = Platform.objects.get(name='Dailymotion')
secret_key = platform.secret_key
api_key = platform.api_key
redirect_uri = platform.callback_url
params = {
'code' : code,
'client_id' : api_key,
'client_secret' : secret_key,
'grant_type':'authorization_code',
'redirect_uri':redirect_uri
}
r = requests.post('https://api.dailymotion.com/oauth/token',data=params)
print (r.json())
print(code)
print(r.data)
refresh_token = r.json().get('refresh_token')
return refresh_token
but it's not working. the error is : {'error_description': 'Invalid authorization code.', 'error': 'invalid_grant'}
.I tried with the same code,grant_type... post from Chrome extensions and it works. What did i do wrong with python code?
def get_refresh_token(self, code): args = { 'grant_type': 'refresh_token', 'refresh_token': code, 'client_id': DAILYMOTION_API_KEY, 'client_secret': DAILYMOTION_API_SECRET, } url = 'https://api.dailymotion.com/oauth/token' data = urllib.urlencode(args) request = urllib2.Request(url, data) response = urllib2.urlopen(request) html = response.read() obj_Response = literal_eval(html) return obj_Response
在获取AccessToken时,我们获得了一个参数“代码”,在这里我们必须将该值替换为代码。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.