2

我正在尝试获取 Linkedin 公司更新到我的网站。按照流程https://developer.linkedin.com/documents/authentication并通过注册生成 api 密钥和密钥。

根据文档,我能够在步骤 a 中生成授权码。对于步骤 b 生成访问令牌,我在 java 中使用 OAuth

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)

请帮助解决这个问题。提前感谢您的帮助。

4

2 回答 2

2

我发现了这个问题。

Looks like there is a problem in the documentation. Apologies.

Right call is

request = OAuthClientRequest.tokenLocation("https://www.linkedin.com/uas/oauth2/accessToken")
                    .setGrantType(ResponseType.CODE.toString())
                    .setCode("****")
                    .setRedirectURI("https://www.example.in")
                    .setClientId("*******")
                    .setClientSecret("******").buildBodyMessage();

Mind ResponseType.CODE.toString() rather than GrantType.AUTHORIZATION_CODE

于 2013-04-07T17:19:38.907 回答
1

我建议您在此处阅读一些linkedin 开发人员文档,并查看 java OAuth 库,而不是手动执行签名过程。然后你可以问一个具体的问题。

于 2013-03-17T06:32:34.020 回答