I
I
Igor2019-04-05 20:45:58
PHP
Igor, 2019-04-05 20:45:58

Foreach in php class?

Hello everyone, plz tell me how to implement:
- Through the VK API I get posts from the VK wall
- But I can’t figure out how to add getting posts not from 1 page, but from several

THE CODE
<?php

namespace Controllers;

Class GetPost {

    public $owner_id = ['47482390', '39488246'];
    public $count = '1';
    private $access_token = 'НАШ_ТОКЕН';

    /**
     * @param $owner_id - ID группы
     * @param $count - Сколько записей выбирать
     * @return string
     */

    public function wallGet() {

            $request_params = array(
                'owner_id' => -(int)$this->owner_id,
                'filter' => 'owner',
                'offset' => 1,
                'count' => $this->count,
                'extended' => 1,
                'access_token' => $this->access_token,
                'v' => '5.92'
            );

            $get_params = http_build_query($request_params);
            $result = json_decode(file_get_contents('https://api.vk.com/method/wall.get?'. $get_params), TRUE);

            if ($result !== false) {
                return $result['response']['items'];
            }
            else {
                $error = 'Ошибка! Записи не получены.';
                return $error;
                }
    }
}

$getPost = new GetPost();

var_dump($getPost->wallGet());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2019-04-05
@m0pfin

- But I can’t figure out how to add getting records not from 1 page, but from several

If we are talking about pages in the sense of page-by-page output of posts, then read about offset
https://vk.com/dev/wall.get
It is not clear where foreach, class and php are.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question