Back to Home

Getting vk.com community members in seconds

api vk · execute · members of the group

Getting vk.com community members in seconds

  • Tutorial
It's no secret that the VK API returns no more than 1,000 members in one request to the groups.getMembers method . In one second, you can get a maximum of 3,000 participants, because the limit on the number of requests per second is set to 3. This is solved by the execute method , with which you can get more than 100,000 participants in one second and up to 25,000 participants in one request . In this article I will tell you how I implemented it.

Without using the execute method , the process of getting members of a group with an audience of 4,000,000 people will take about 22 minutes, and we will need to complete about 4,000 API requests. Using the execute methodwe will speed up this process by about 40 seconds and complete only about 160 queries.

Content:

  • I. A little bit about execute
  • II. Javascript implementation
  • Sources and examples


I. A little bit about execute


This is a universal method that allows you to run a sequence of other methods, storing and filtering intermediate results.
A simple request is made like all other methods, but in the parameters you need to pass code written in VKScript .

What does VKScript support and what is it?


It is a language similar to JavaScript or ActionScript. The algorithm should end with the command return% expression%. Operators must be separated by semicolons.

The following are supported:
  • arithmetic operations
  • logical operations
  • creation of arrays and lists ([X, Y])
  • parseInt and parseDouble
  • concatenation (+)
  • if construct
  • array filter by parameter (@.)
  • API method calls, length parameter
  • loops using the while statement
  • Javascript methods: slice, push, pop, shift, unshift, splice, substr
  • delete operator
  • assignment to array elements, for example: row.user.action = "test";


Using this method, we can get the result of several methods in one API request.

II. Javascript implementation



We write a simple function that recurses will pull the procedure described below execute.getMembers.
getMembers(group_id);


To get the members of the group we will use execute , for one request we will get 25,000 members. Execute allows you to make up to 25 queries described using the VKScript language . In the code parameter, we need to pass the algorithm in the VKScript language .

The getMembers procedure has been created, which we will pull from the client 3 times per second.
var members = API.groups.getMembers({"group_id": Args.group_id, "v": "5.27", "sort": "id_asc", "count": "1000", "offset": Args.offset}).items; // делаем первый запрос и создаем массив
var offset = 1000; // это сдвиг по участникам группы
while (offset < 25000 && (offset + Args.offset) < Args.total_count) // пока не получили 20000 и не прошлись по всем участникам
{
  members = members + "," + API.groups.getMembers({"group_id": Args.group_id, "v": "5.27", "sort": "id_asc", "count": "1000", "offset": (Args.offset + offset)}).items; // сдвиг участников на offset + мощность массива
  offset = offset + 1000; // увеличиваем сдвиг на 1000
};
return members;


Sources and examples


In case VK lies, it looked like this:
image

An example of work: http://vk.com/app4236781
Sources: github.com/romkagolovadvayha/getmembersVKAPI.git

Read Next