M
M
Medvedoc2018-02-12 07:30:31
In contact with
Medvedoc, 2018-02-12 07:30:31

How to get posts along with video and audio using wall.get VK API?

From the above code, I need to get additional data from [attachments] (link, video, photo). How to make a request?
I have provided my code below

<?php

$params = [
  'owner_id' => '-id группы',
  'offset' => '0',
  'count' => '100',
  'filter' => 'all',
  'access_token' => 'токен',
  'v' => '5.71'
];
$url = 'https://api.vk.com/method/wall.get?' . http_build_query($params);
$response = json_decode(file_get_contents($url), true);

//echo '<pre>';
//print_r($response);
//echo '</pre>';

?>

<!doctype>
<html lang="ru">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <?php foreach($response['response']['items'] as $user): ?>
    <table>
      <tr>
        <td><?php echo $user['text'] ?></td>
      </tr>
      <tr>
                <td>Комментариев: <?php echo $user['comments']['count'] ?></td>
                <td>Лайков: <?php echo $user['likes']['count'] ?></td>
                <td>Репостов: <?php echo $user['reposts']['count'] ?></td>
                <td>Просмотров: <?php echo $user['views']['count'] ?></td>
      </tr>
    </table>
    <?php endforeach; ?>
  </body>
</html>

Array
(
    [response] => Array
        (
            [count] => 217
            [items] => Array
                (
                    [1] => Array
                        (
                            [id] => 288
                            [from_id] => -48870859
                            [owner_id] => -48870859
                            [date] => 1515090516
                            [marked_as_ads] => 0
                            [post_type] => post
                            [text] => 
                            [can_delete] => 1
                            [can_pin] => 1
                            [attachments] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => link
                                            [link] => Array
                                                (
                                                    [url] => https://vk.com/life_purposeful
                                                    [title] => Шаг к успеху
                                                    [caption] => vk.com
                                                    [description] => Журнал предназначен для людей, которые поставили перед собой задачу стать успешными. Здесь Вы найдете много полезных высказываний, интересных фильмов и аудиокниг данного направления. Прочитывая и перечитывая ежедневно вновь пополняемые закрома наших знаний Вы начнете делать уверенные шаги в свое..
                                                    [photo] => Array
                                                        (
                                                            [id] => 296306539
                                                            [album_id] => -6
                                                            [owner_id] => -48214952
                                                            [user_id] => 100
                                                            [photo_75] => https://pp.userapi.com/c309528/v309528223/4472/n0Hu2pgPitU.jpg
                                                            [photo_130] => https://pp.userapi.com/c309528/v309528223/4473/McnhJU2RvFY.jpg
                                                            [photo_604] => https://pp.userapi.com/c309528/v309528223/4474/x72tQ4YIxgg.jpg
                                                            [photo_807] => https://pp.userapi.com/c309528/v309528223/4475/FtzEW_3RZCc.jpg
                                                            [photo_1280] => https://pp.userapi.com/c309528/v309528223/4476/4u7IaYqMDNk.jpg
                                                            [width] => 650
                                                            [height] => 997
                                                            [text] => 
                                                            [date] => 1358073227
                                                            [post_id] => 1
                                                        )

                                                )

                                        )

                                )

                            [post_source] => Array
                                (
                                    [type] => vk
                                )

                            [comments] => Array
                                (
                                    [count] => 0
                                    [groups_can_post] => 1
                                    [can_post] => 1
                                )

                            [likes] => Array
                                (
                                    [count] => 0
                                    [user_likes] => 0
                                    [can_like] => 1
                                    [can_publish] => 1
                                )

                            [reposts] => Array
                                (
                                    [count] => 0
                                    [user_reposted] => 0
                                )

                            [views] => Array
                                (
                                    [count] => 96
                                )

                        )
                )

        )

)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Kudryavtsev, 2018-02-12
@Deissh

In [attachments] there is an array with information about the attachment, for example, a photo has an id with which you can get information about the photo, you can also see links to photo thumbnails. Unfortunately, VK has disabled receiving music through the public api. Or write a castle. And the video will be the same as the photo, only it will be necessary to receive the stream through a new request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question