I am connecting to linkedin api through python.
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)
but I am getting the following error :
{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id","error":"invalid_request"}
what is the reason for this error ? how to debug ? please help.
That is a strange way to format the data. You have each parameter in a separate dictionary. I guess you want a single dict:
data = {
'client_id': 'xxx',
'client_secret': 'xxx',
'grant_type': 'authorization_code',
'redirect_uri' : 'xxx',
'code': xxx
}
Also, you specify the content type as form-encoded, but you then serialize the actual data as JSON. Don't do that.
r = requests.post(url, data=data, headers=headers)
You need to repeat the process of acquiring a new authorization code, the code tends to expire if unused for sometime. Check this out: https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow#step-5-refresh-access-token
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.