我一直在努力將我的應用程序與LinkedIn整合在一起,其文檔位於here。我創建了我的LinkedIn應用是能夠成功地獲取授權碼,但我正在試圖獲得訪問令牌時,出現以下錯誤:鏈接無法檢索訪問令牌缺少所需的參數錯誤
{「ERROR_DESCRIPTION」:「缺少必需的參數,包括無效 參數值,參數不止一次:無法檢索訪問令牌:APPID或重定向URI不匹配授權碼或授權碼已過期」,‘錯誤’:‘INVALID_REQUEST’}
我已經驗證以下爲真:
- 重定向URI對於授權請求和訪問令牌請求是相同的
- 我在使用授權代碼的20秒內發出。
- 我包括 「內容類型:應用程序/ x-WWW的形式,進行了urlencoded」 的請求頭
有些事情我都沒有成功嘗試:
- 發佈與請求的參數作爲URL
- 發佈與參數的請求作爲主體
- 的一部分發送重定向URI作爲同時使用編碼和純文本
- 的一部分一個獲取請求,而不是一個帖子。
這裏是我當前的代碼:
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並粘貼到瀏覽器中,我可以檢索一個訪問令牌而不會有任何問題。我的要求有問題嗎?
由於它正在vi直接url,你有沒有試圖改變你的請求從發佈到看看會發生什麼? –
我嘗試了一個獲取請求,結果相同。 – kmb71123
您確信您已配置https:// localhost:8090/ProfileSetup/linkedInAuth。jsp是LinkedIn應用程序配置中的有效重定向目標,位於https://www.linkedin.com/developer/apps? –