[英]Linked in unable to to retrieve access token missing required parameters error
我一直在通過遵循這里的文檔來將我的應用程序與LinkedIn集成。 我已經在LinkedIn中創建了我的應用程序,並且能夠成功檢索授權代碼,但是在嘗試獲取訪問令牌時出現以下錯誤:
{“ error_description”:“缺少必需的參數,包括無效的參數值,參數多次。。:無法檢索訪問令牌:appId或重定向uri與授權碼不匹配或授權碼已過期”,“錯誤”:“ invalid_request” }
我已驗證以下各項是正確的:
我嘗試過的一些事情沒有成功:
這是我當前的代碼:
linkedin_access_token_url = "https://www.linkedin.com/uas/oauth2/accessToken?"+
"grant_type=authorization_code"+
"&code="+ authCode
+ "&redirect_uri=https://localhost:8090/ProfileSetup/linkedInAuth.jsp
+ "&client_id=" + linkedin_client_id
+ "&client_secret=" + linkedin_client_secret;
HttpClient http = new DefaultHttpClient();
HttpPost httppost = new HttpPost(linkedin_access_token_url);
try {
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpResponse response = http.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("status code " +
response.getStatusLine().getStatusCode());
System.out.println("statusreason"+
response.getStatusLine().getReasonPhrase());
InputStream stream = entity.getContent();
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(stream));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (Exception e) {
}
String resp = sb.toString();
System.out.println("response " + resp);
} catch (Exception ex) {
System.out.println("linked in HttpResponse Error: " + ex);
} finally {
httppost.releaseConnection();
}
和授權URL(實際的客戶端ID代替linkedin_client_id發送):
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=linkedin_client_id&redirect_uri=https://localhost:8090/ProfileSetup/linkedInAuth.jsp&state=0kcmjj5504tpgb9&scope=r_basicprofile
有人看到我在做什么錯嗎? 如果我使用此編譯的URL並將其粘貼到瀏覽器中,則可以毫無問題地檢索訪問令牌。 我的要求有問題嗎?
看起來您已將請求的所有參數作為屬性包含在URL中,而不是在POST
正文中包含為x-www-form-urlencoded
元素。
請查看另一個Stack線程,以獲取有關如何在請求正文中而不是作為URL屬性發送值的詳細信息:
我終於能夠弄清楚我的應用程序出了什么問題。 未為https正確配置我的本地環境。 將代碼移到我們設置為https的開發箱中解決了該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.