In general, the task is this: perform a search for users according to certain criteria and add them to the ArrayList .

At the beginning, I get the number of users - count and pass them to the AsyncTask class and start a cycle there that increases the OFFSET_COUNT and creates a new request based on it, with a step that is already shifted, then a method is performed that, based on the new request, searches for users and, under certain conditions, adds them to list.

Firstly, the method that receives the number of found users is triggered only after the 2nd button is pressed or just takes a long time to process.

Secondly, the selection of users processes only ~ 1k from ~ 20k found. I know that there is a limit of 3 requests per second. to the API, I tried to set the delay, but the campaign does not help, because after 1-2 runs, even getCount stops working. I suspect that VK just blocks me.

How to run the query execute correctly in a loop? And if you work immediately with 1000 entries at a time, how to first wait for the request to the API, and then start processing the information.

Method of obtaining count of people found:

 Integer getCount(VKRequest vkRequest) { vkRequest.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); try { count = response.json.getJSONObject("response").getInt("count"); } catch (JSONException e) { e.printStackTrace(); } } }); return count; } 

Code snippet running in the class doInBackground AsyncTask

 @Override protected View doInBackground(VKParameters... param) { VKRequest request; int countStep = count / 50; for (int i = 0; i < countStep; i++) { OFFSET_COUNT += 50; param[0].put(VKApiConst.OFFSET, OFFSET_COUNT); try { TimeUnit.MICROSECONDS.sleep(350); } catch (InterruptedException e) { e.printStackTrace(); } request = VKApi.users().search(param[0]); runRequest(request); } return null; } 

runRequest(request) - the method that runs request.executeWithListener

  • I am specifically in java is not strong, but the user parsing works for me every day. If you work through api and comply with the limits, then there will be no problems. Check the algorithms, in words you say everything correctly. - AK
  • So I would like to know how to properly comply with these limits) Because the delay, it seems to me, does not help. - Konstantin
  • @ Konstantin, why not use different tokens? - Let's say Pie

0