python LinkedIn api 连接

python LinkedIn api connection

我正在通过 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"}

这个错误的原因是什么?如何调试?请帮忙

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

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)