1

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?

Le Duy Khanh
  • 1,339
  • 3
  • 17
  • 36
  • I don't know if this helps, but I'd try breaking it down starting with Chrome. Use a header plugin to see the exact back-and-forth that it's doing with the site. Then use curl to recreate it successfully on the command line. Then try it in Python. – Matthew Cornell Sep 16 '15 at 13:15

1 Answers1

0

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

while getting AccessToken we get a parameter 'code' here we have to put that value in place of code.