Answer the question
In order to leave comments, you need to log in
How to do something after the loop ends?
The API of the social network VKontakte allows you to get only 100 posts with one request, which does not suit me.
const resource = await resolveResource({
api: vk.api,
resource: context.$match[1],
});
const allPosts = [];
context.reply(`Начинаю сбор информации...`);
const counter = await vk.api.wall.get({
// Получаем кол-во постов.
owner_id: resource.id,
count: 1,
});
for (let i = 0; i < counter.count; i += 100) {
vk.api.wall
.get({
owner_id: resource.id,
count: 100, // Больше 100 получить нельзя.
})
.then((res) => {
allPosts.push(res); // Пушим пачки постов.
});
}
Answer the question
In order to leave comments, you need to log in
Code for simple case:
const promises = [];
for (let i = 0; i < counter.count; i += 100) {
promises.push(vk.api.wall
.get({
owner_id: resource.id,
count: 100, // Больше 100 получить нельзя.
})
})
}
Promise.all(promises)
.then(res => res.flat())
.then (res =>{
//res === пачки постов.
// здесь можно что то сделать с постами
})
The API of the social network VKontakte allows you to get only 100 posts with one request, which does not suit me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question