我正在嘗試獲取Linkedin公司的更新到我的網站。遵循流程https://developer.linkedin.com/documents/authentication並通過註冊生成api密鑰和密鑰。Linkedin api使用java中的oauth調用
根據documentation我可以在步驟a中生成授權碼。 對於步驟b生成訪問令牌我正在使用OAuth in java。
request = OAuthClientRequest.tokenLocation("https://www.linkedin.com/uas/oauth2/accessToken")
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setCode("****")
.setRedirectURI("https://www.example.in")
.setClientId("*******")
.setClientSecret("******").buildBodyMessage();
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request, GitHubTokenResponse.class);
String accessToken = oAuthResponse.getAccessToken();
String expiresIn = oAuthResponse.getExpiresIn();
但得到錯誤
OAuthProblemException{description='Missing parameters: access_token', error='invalid_request', uri='null', state='null', scope='null'}
at org.apache.amber.oauth2.common.exception.OAuthProblemException.error(OAuthProblemException.java:57)
at org.apache.amber.oauth2.common.utils.OAuthUtils.handleOAuthProblemException(OAuthUtils.java:166)
at org.apache.amber.oauth2.common.utils.OAuthUtils.handleMissingParameters(OAuthUtils.java:184)
at org.apache.amber.oauth2.client.validator.OAuthClientValidator.validateRequiredParameters(OAuthClientValidator.java:90)
at org.apache.amber.oauth2.client.validator.OAuthClientValidator.validateParameters(OAuthClientValidator.java:53)
at org.apache.amber.oauth2.client.validator.OAuthClientValidator.validate(OAuthClientValidator.java:49)
at org.apache.amber.oauth2.client.response.OAuthClientResponse.validate(OAuthClientResponse.java:64)
at org.apache.amber.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:59)
at org.apache.amber.oauth2.client.response.OAuthAccessTokenResponse.init(OAuthAccessTokenResponse.java:52)
at org.apache.amber.oauth2.client.response.OAuthClientResponseFactory.createCustomResponse(OAuthClientResponseFactory.java:60)
at org.apache.amber.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:105)
請幫助解決這個問題。預先感謝您的幫助。
謝謝安東尼奧,剛剛試過這一個,並得到編譯錯誤類型OAuthClientRequest.TokenRequestBuilder中的方法setGrantType(GrantType)不是 適用於參數(字符串)。我是否需要製作任何週報。 – Bhabani 2013-04-08 05:32:41
oopps道歉。我已經將身份驗證位置與令牌一混合了。問題是你可能想使用OAuthJSONAccessTokenResponse.class而不是GitHubTokenResponse.class for Linkedin:OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request,OAuthJSONAccessTokenResponse.class);我們正在改進我們的API和文檔。我意識到這有點令人困惑。 – 2013-04-08 07:28:09
謝謝安東尼奧,終於可以打電話了。 – Bhabani 2013-04-08 08:30:18