jith
jith

Reputation: 69

python LinkedIn api connection

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.

Upvotes: 0

Views: 341

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599450

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)

Upvotes: 1

Related Questions