2015-09-21 173 views
0

我通過python連接到linkedin api。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"} 

什麼是這個錯誤的原因是什麼?如何調試?請幫忙。

回答

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

收到錯誤'{「ERROR_DESCRIPTION」:「缺少必需的參數,包括一個無效的參數值,參數不止一次:無法檢索訪問令牌:APPID或重定向URI不匹配授權碼或授權碼已過期」, 「錯誤」: 「INVALID_REQUEST」}' – Volatil3