python LinkedIn api连接

问题描述 投票:0回答:2

我正在通过python连接到linkedin api。

url = 'https://www.linkedin.com/uas/oauth2/accessToken'

data = [
        {'client_id': 'xxx'},
        {'client_secret': 'xxx'},
        {'grant_type': 'authorization_code'},
        {'redirect_uri' : 'xxx'},
        {'code': xxx}
      ]

headers = {'Content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=json.dumps(data), headers=headers)
return HttpResponse(r)

但是我收到以下错误:

{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id","error":"invalid_request"}

此错误的原因是什么?如何调试?请帮助。

python django request linkedin
2个回答
1
投票

这是格式化数据的一种奇怪方法。每个参数都在单独的字典中。我想你想要一个字典:

data = {
         'client_id': 'xxx',
         'client_secret': 'xxx',
         'grant_type': 'authorization_code',
         'redirect_uri' : 'xxx',
         'code': xxx
       }

[此外,您将内容类型指定为表单编码,但是随后将实际数据序列化为JSON。不要那样做。

r = requests.post(url, data=data, headers=headers)

0
投票

您需要重复获取新授权码的过程,如果一段时间未使用,授权码往往会过期。签出:https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow#step-5-refresh-access-token

© www.soinside.com 2019 - 2024. All rights reserved.