我正在尝试this example使用Spring Social获取LinkedIn用户的个人资料。该项目的源代码也可用here
用户被重定向到LinkedIn授权页面https://www.linkedin.com/uas/oauth/authorize?oauth_token= *,并且用户允许该应用访问其个人资料。用户点击按钮"允许访问"后,他会被重定向到http://localhost:7090/spring-oauth-linkedin-sample/connect/linkedin?oauth_token= * & oauth_verifier = ***,此处会抛出异常:
HTTP ERROR 500
Problem accessing /spring-oauth-linkedin-sample/connect/linkedin. Reason:
Server Error
Caused by:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 403 Forbidden
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1666)
在eclipse控制台中我得到:
DEBUG - 7568555-17 - RestTemplate - Created POST request for "https://api.linkedin.com/uas/oauth/accessToken"
DEBUG - 7568555-17 - RestTemplate - Setting request Accept header to [text/plain, */*]
DEBUG - 7568555-17 - RestTemplate - Writing [{}] using [org.springframework.http.converter.FormHttpMessageConverter@5eedaba0]
DEBUG - 7568555-17 - RestTemplate - POST request for "https://api.linkedin.com/uas/oauth/accessToken" resulted in 200 (OK)
DEBUG - 7568555-17 - RestTemplate - Reading [java.lang.String] as "text/plain" using [org.springframework.http.converter.StringHttpMessageConverter@7e8b6c76]
DEBUG - 7568555-17 - RestTemplate - Created GET request for "https://api.linkedin.com/v1/people/~:public"
DEBUG - 7568555-17 - RestTemplate - Setting request Accept header to [application/xml, text/xml, application/*+xml, application/json]
WARN - 7568555-17 - RestTemplate - GET request for "https://api.linkedin.com/v1/people/~:public" resulted in 403 (Forbidden); invoking error handler
DEBUG - 7568555-17 - odHandlerExceptionResolver - Resolving exception from handler [org.springframework.social.web.connect.ConnectController@1c178a81]: org.springframework.web.client.HttpClientErrorException: 403 Forbidden
DEBUG - 7568555-17 - nseStatusExceptionResolver - Resolving exception from handler [org.springframework.social.web.connect.ConnectController@1c178a81]: org.springframework.web.client.HttpClientErrorException: 403 Forbidden
DEBUG - 7568555-17 - ltHandlerExceptionResolver - Resolving exception from handler [org.springframework.social.web.connect.ConnectController@1c178a81]: org.springframework.web.client.HttpClientErrorException: 403 Forbidden
DEBUG - 7568555-17 - DispatcherServlet - Could not complete request
org.springframework.web.client.HttpClientErrorException: 403 Forbidden
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:75)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
at org.springframework.social.linkedin.LinkedInTemplate.getUserProfile(LinkedInTemplate.java:56)
at org.springframework.social.linkedin.LinkedInTemplate.getProfileId(LinkedInTemplate.java:48)
at org.springframework.social.linkedin.connect.LinkedInServiceProvider.getProviderAccountId(LinkedInServiceProvider.java:44)
at org.springframework.social.linkedin.connect.LinkedInServiceProvider.getProviderAccountId(LinkedInServiceProvider.java:28)
at org.springframework.social.connect.oauth1.AbstractOAuth1ServiceProvider.connect(AbstractOAuth1ServiceProvider.java:51)
at org.springframework.social.web.connect.ConnectController.oauth1Callback(ConnectController.java:147)