JAVA-403通过linkedin登录时禁止

时间:2019-06-14 13:30:53

标签: java rest linkedin

我正在通过linkedin实现singIn,如下所示。我遇到了获取accessToken的问题。然后,我尝试获取用户信息,但是却收到403 Forbidden。我想念什么?任何帮助表示赞赏。

@GetMapping("/final-step")
public String home(@RequestParam("code") String authorizationCode) throws JSONException {

    //to trade your authorization code for access token
    String accessTokenUri ="https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code="+authorizationCode+"&redirect_uri="+redirectUrl+"&client_id="+clientId+"&client_secret="+clientSecret+"";

    // linkedin api to get linkedidn profile detail
    String linedkinDetailUri = "https://api.linkedin.com/v2/me";

    //store your access token
    RestTemplate restTemplate = new RestTemplate();
    String accessTokenRequest = restTemplate.getForObject(accessTokenUri, String.class);
    JSONObject jsonObjOfAccessToken = new JSONObject(accessTokenRequest);
    String accessToken = jsonObjOfAccessToken.get("access_token").toString();

    //trade your access token
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer " +accessToken);
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    ResponseEntity<String> linkedinDetailRequest = restTemplate.exchange(linedkinDetailUri, HttpMethod.GET, entity, String.class);
    //store json data
    JSONObject jsonObjOfLinkedinDetail = new JSONObject(linkedinDetailRequest.getBody());
    //print json data
    System.out.println(jsonObjOfLinkedinDetail);

    return "signup";
}

这是个例外

ERROR 42537 --- [nio-8080-exec-4] o.s.b.w.servlet.support.ErrorPageFilter  : Forwarding to error page from request [/final-step] due to exception [403 Forbidden]

org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden
...

0 个答案:

没有答案