D
D
dj_vadim2016-02-21 10:05:06
PHP
dj_vadim, 2016-02-21 10:05:06

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

2 answer(s)
D
dj_vadim, 2016-02-21
@dj_vadim

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.

S
Silm, 2016-02-21
@Silm

Forgot to write the result.
Why is the $param array initialized in your loop body?
Did you look at the contents of $param at the moment before sending the request to VK?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question