Java Restrictflow APIを使用してアプリケーションJava + Salesforceを開発していますが、エラーが発生しているようです。どんな助け?Spring RestTemplateを使用してSalesforce APIを呼び出すことができません
public class RestTemplateExample {
final static String TOKEN_URL = "https://ap5.salesforce.com/services/oauth2/token";
public static void main(String[] args) {
HttpHeaders headers = new HttpHeaders();
headers.add("client_secret", "XXXXXXXXX");
headers.add("client_id", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
headers.add("grant_type", "password");
headers.add("username", "[email protected]");
headers.add("password", "XXXXXXXXXXXX");
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>("", headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> result = restTemplate.exchange(TOKEN_URL, HttpMethod.POST, entity, String.class);
System.out.println("TOKEN DETAILS :: "+result.getBody());
}
}
私は郵便番号を確認してもうまくいきます。
2017-10-14 18:40:35 DEBUG o.s.web.client.RestTemplate - Created POST request for "https://ap5.salesforce.com/services/oauth2/token"
2017-10-14 18:40:35 DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [text/plain, application/json, application/*+json, */*]
2017-10-14 18:40:35 DEBUG o.s.web.client.RestTemplate - Writing [] using [[email protected]41a12]
2017-10-14 18:40:37 DEBUG o.s.web.client.RestTemplate - POST request for "https://ap5.salesforce.com/services/oauth2/token" resulted in 400 (Bad Request); invoking error handler
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:78)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
at com.example.RestTemplateExample.main(RestTemplateExample.java:29)