Michael Deudon
Michael Deudon

Reputation: 1

JAVA get URL API

I am trying to get API data using this simple code:

while (true)
{
  BufferedReader br = new BufferedReader(new InputStreamReader(new 
  URL("https://api.darksky.net/forecast/f34171a387dbb5f4a29c66f6adc52e2f /49.133333,6.16667")
      .openStream()));

   String temp = br.readLine();
   MyAPI = new JSONObject(strTemp);
   System.out.println(MyAPI.getJSONObject("currently").getLong("time"));

   br.close();
   Thread.sleep(5000);
}

Normally the "time" I get should be different each time I request the API.

It is OK when I use a web browser to request the API, but with my java application I always receive the same data all day long.VP

Did I miss something?

Upvotes: 0

Views: 534

Answers (1)

Peter Jacobsen
Peter Jacobsen

Reputation: 677

your URL

URL("https://api.darksky.net/forecast/f34171a387dbb5f4a29c66f6adc52e2f /49.133333,6.16667")

suppose not to have a space

URL("https://api.darksky.net/forecast/f34171a387dbb5f4a29c66f6adc52e2f/49.133333,6.16667")

Upvotes: 1

Related Questions