私はYahooの天気サービスから以下のHTTPSエンドポイントを消費しようとしています:春ブーツとHTTPS GETサービスを消費する方法
私は現在を取得するためのAPIに応じていくつかの特別なクエリをしていますパラメータ化された場所の天気。
@Service("weatherConditionService")
public class WeatherConditionServiceImpl implements WeatherConditionService {
private static final String URL = "http://query.yahooapis.com/v1/public/yql";
public WeatherCondition getCurrentWeatherConditionsFor(Location location) {
RestTemplate restTemplate = new RestTemplate();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(URL);
stringBuilder.append("?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22");
// TODO: Validate YQL query injection
stringBuilder.append(location.getName());
stringBuilder.append("%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
WeatherQuery weatherQuery = restTemplate.getForObject(stringBuilder.toString(), WeatherQuery.class);
// TODO: Test Json mapping response
Condition condition = weatherQuery.getQuery().getResults().getChannel().getItem().getCondition();
return new WeatherCondition(condition.getDate(), Integer.parseInt(condition.getTemp()), condition.getText());
}
場所は、「ニューヨーク」や「マニラ」など、場所の文字列の説明である属性「名前」を提供するクラスです。
条件他のクラスは戻ってくるオブジェクトをマップします。実行時には
私は、次のHTTPレスポンスを得る:
org.springframework.web.client.HttpClientErrorException: 403 Forbidden
だからこれは私が私が理解からリソースにアクセスする権限がありませんよ意味します。
私はちょうど&は、Webブラウザに貼り付けてコピーした場合、URLは素晴らしい作品:
私は「400」(不正なリクエスト)を取得しておりませんので、マッピングは問題ではないと思われるが、 "403"(禁止されています)
RestTemplateオブジェクトの使用方法には何らかのエラーがあります。私は研究していますが、私は答えを見つけることができません。
感謝。私はjavascriptを使って、または直接Webブラウザにそれを打つことができます。 Javaの例はないので、私はAPIキーを必要としないと推測しました。それがそれかもしれません。私はJavaでそれを行う方法を調べる必要があります。 – sebadagostino