Answer the question
In order to leave comments, you need to log in
How to use execute (VK API)?
Hello!
The task is to parse all the members of the group. Here is the code we have now:
import requests
API = "https://api.vk.com/method"
ACCESS_TOKEN = "**********"
V = 5.80
response = requests.post(url=f"{API}/execute",
data={
"code": "var members = API.groups.getMembers({\"group_id\": \"tensor_company\"}).users;"
"var count = members.count;"
"var offset = 1000;"
"while (offset < count);"
"{;"
"members = members + \" , \" + API.groups.getMembers({\"group_id\": \"tensor_company\", \"offset\": offset}).users;"
"offset = offset + 1000;"
"};"
"return members;",
"access_token": ACCESS_TOKEN,
"v": V,
})
print(response.json())
{'error': {'error_code': 13, 'error_msg': 'Runtime error occurred during code invocation: Too many operations', 'request_params': [{'key': 'group_id', 'value': 'tensor_company' }]}}
Answer the question
In order to leave comments, you need to log in
Note!
https://vk.com/dev/execute
Most likely, you exceed the set limit, optimize the code so that no more than 25 API calls are made inside the procedure.
See project on github
var step=1000, R, offset = parseInt(Args.offset), loop=0,
out = { oid: parseInt(Args.oid), ids:[], mass: parseInt(Args.mass), overlap: parseInt(Args.overlap), offset: 0, next: 0 };
while( offset <= out.mass && loop < 25) {
R = API.groups.getMembers({ "group_id": out.oid, "sort": "id_asc", "offset": offset, "count": step});
if( !!R.items && R.items.length > 0) {
out.ids.push( R.items);
out.mass = R.count;
out.loop = loop;
out.offset = offset;
offset = offset + step - out.overlap;
out.next = offset;
loop = loop + 1;
} else {
out.error = "Empty items";
out.r = R;
return out;
}
}
return out;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question