H
H
hasle1252019-03-14 18:13:34
API
hasle125, 2019-03-14 18:13:34

How to get a list of posts in a specific group in VK using vk api?

Good day! Tell me, how can I get a list of links to posts or the posts themselves in a specific group using vk api? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Elmodo, 2019-03-14
@hasle125

Use the wall.get VK API method ( https://vk.com/dev/wall.get).
In PHP like this:

var_dump(wallGet($owner_id, $count)); //должен вывести массив записей сообщества $owner_id, в количестве $count
function wallGet($owner_id, $count) {
        $result = api('wall.get', array(
                    'owner_id' => -(int)$owner_id,
                    'count' =>(int)$count,
        ));
        if ($result !== false) {
            return $result['items'];
        }
        else {
            return false;
        }
}

function api($method, $params) { 
        $params['access_token'] = $access_token;
        $params['v'] = $api_version;
        $url = 'https://api.vk.com/method/' . $method;
        if (!function_exists('curl_init')) {
            die('ERROR: CURL library not found!');
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 3.5.30729)",
            "Accept-Language: en-us,en;q=0.5}"
        ));
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        $json = curl_exec($ch);
        $error = curl_error($ch);
        if ($error) {
            error_log($error);
            return false;
        }
        curl_close($ch);
        $response = json_decode($json, true);
        if (!$response || !isset($response['response'])) {
            error_log($json);
            return false;
        }
        return $response['response'];
}

R
Roman, 2019-03-14
@roman94

You can use wall get Vk api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question