【问题标题】:Dailymotion API get refresh token by request.post pythonDailymotion API 通过 request.post python 获取刷新令牌
【发布时间】:2015-12-10 00:19:36
【问题描述】:

我想通过这段代码从 Dailymotion API 获取刷新令牌

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

但它不起作用。错误是:{'error_description': 'Invalid authorization code.', 'error': 'invalid_grant'} .我尝试使用相同的代码,grant_type ...从Chrome扩展程序发布,它可以工作。我的 python 代码做错了什么?

【问题讨论】:

  • 我不知道这是否有帮助,但我会尝试从 Chrome 开始对其进行分解。使用标题插件来查看它与站点的确切来回操作。然后在命令行上使用 curl 重新创建成功。然后在 Python 中尝试一下。

标签: python dailymotion-api


【解决方案1】:

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 时,我们在这里得到一个参数“code”,我们必须用该值代替 code。

【讨论】:

    猜你喜欢
    • 2015-03-05
    • 2020-06-09
    • 2012-02-15
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    相关资源
    最近更新 更多