Answer the question
In order to leave comments, you need to log in
Why does the offset shift not work when requesting VC data?
Good afternoon.
I am developing a script for getting posts from a group for a specific date. Can't implement offset offset. Those. I request 30 posts (30 is for example) and shift by 30 until I select the last post by the latest date in the date range.
$date_first = strtotime('18.02.2016'); // начальная дата
$date_second = strtotime('15.02.2016'); // конечная дата
$owner_id = '-83935640'; // сообщество для примера
$status = true; // для цикла
$data['count_iteration'] = 0; // количество итераций
$data['result'] = '';
do {
$param = array(
'owner_id' => $owner_id,
'offset' => 30*$data['count_iteration'], // сдвиг
'count' => 30, // количество выбираемых
'filter' => 'all',
'extended' => 0
);
$data['count_iteration']++; // увеличиваем количество итераций на 1
$res = $this->vkontakte_lib->api('wall.get', $param); // запрашиваем посты из группы
foreach($res['items'] as $item): // в цикле проверяем на соответствие каждого поста диапазону дат
if($date_first>=$item['date'] && $item['date']>=$date_second){
$data['result'][] = $item['id']; // записываем id поста в массив
} else if($item['date']<$date_second) { // если пост был последним из диапазона дат то мы
$status = false; // выходим из цикла
echo "конец на ".$data['count_iteration'].' итерации<br>';
}
endforeach;
} while($status);
Answer the question
In order to leave comments, you need to log in
Problem solved.
The script initially worked, but only on the condition that there were no pinned records in the group. I think further comments are unnecessary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question