Answer the question
In order to leave comments, you need to log in
How to make a cycle. vk api request on java?
Good afternoon. There is such a code that sends an API request to get photos in a certain area, and saves the resulting json file.
String key = "7075966f7075966f7075966f577018909e770757075966f2dfd2579655817dfd28d3bfd";
String Vers = "5.103";
System.out.println("Широта ");
String LATITUDE = inscaner.next();
System.out.println("Долгота ");
String LONGITUDE = inscaner.next();
System.out.println("Укажите радиус поиска (например, 100 метров) = ");
String radius = inscaner.next();
String url = "https://api.vk.com/method/photos.search?"
+ "&lat=" + LATITUDE
+ "&long=" + LONGITUDE
+ "&count=" + count
+ "&radius=" +radius
+ "&access_token=" + key
+ "&v=" + Vers;
try {
URL obj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
/*
System.out.println(response.toString());
*/
try (FileWriter file = new FileWriter("response-vk.json")) {
file.write(response.toString());
}
}catch(Exception e){}
}
{"response":{"count":5365,"items":[{"id":457239398,"album_id":-7,"owner_id":515520034,"sizes":[{"type":"s","url":"https:\/\/sun9-37.userapi.com\/c858024\/v858024733\/12881f\/YmnQybQVwQw.jpg","width":42,"height":75},{"type":"m","url":"https:\/\/sun9-44.userapi.com\/c858024\/v858024733\/128820\/pP86RyrkS_M.jpg","width":73,"height":130},{"type":"x","url":"https:\/\/sun9-
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question