Answer the question
In order to leave comments, you need to log in
What is the most efficient way to get a list of group members?
In continuation of the previous question .
In general, I refused to transfer the algorithm code to VKScript (it is inconvenient to write the code) in the request and used stored procedures. The stored procedure code is as follows:
var offset = parseInt(Args.offset);
var count = parseInt(Args.count);
var group_id = parseInt(Args.group_id);
if (group_id == 0) {
group_id = Args.group_id;
}
var loop = 25;
var members = [];
while (offset < count && loop) {
members = members + API.groups.getMembers({"group_id": group_id, "offset": offset}).users;
offset = offset + 1000;
loop = loop - 1;
}
return {"offset": offset, "members": members};
response = requests.get(url=f"{VK_API}/groups.getMembers",
params={
"group_id": VK_GROUP_ID,
"access_token": VK_TOKEN,
"v": VK_V
}).json()["response"]
count = response["count"]
members = response["users"]
offset = 1000
while offset < count:
response = requests.get(url=f"{VK_API}/execute.getMembers",
params={
"group_id": VK_GROUP_ID,
"count": count,
"offset": offset,
"access_token": VK_TOKEN,
"v": VK_V
}).json()["response"]
offset = response["offset"]
members += response["members"]
Answer the question
In order to leave comments, you need to log in
You should pay attention to the py-vkontakte library , which allows you to work with the vk.com API.
>>> import vk
>>> api = vk.Api(TOKEN)
>>> group = api.get_group('team') # vk.com/team
>>> user_items = [user for user in group.get_members()]
>>> user_id_items = [user_id for user_id in group.get_members_only_id()]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question