Y
Y
Yulia Yushchenko2014-03-24 16:34:09
In contact with
Yulia Yushchenko, 2014-03-24 16:34:09

How to display an image in wall.get?

Hello everyone guys. Recently, on the Internet, I saw such a function as displaying posts from a group on a site using wall.get (api vk)
the code itself

<?php
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.7&filter=all&domain=opmus&count=50&extended=1"); // Отправляем запрос
$wall = json_decode($wall); // Преобразуем JSON-строку в массив
$wall = $wall->response->items; // Получаем массив
for ($i = 0; $i < count($wall); $i++) {
$x = $wall[$i]->text;
if($x !== ''){ // Не выводим пустые посты.
echo "".date("H:i:s", $wall[$i]->date).""; // Выводим дату поста
echo "".$wall[$i]->text."</br>"; // Выводим текст поста
}}
?>

Everything seems to be fine, everything outputs without errors :((
EZdHI.png
but ... I would also like to display the image that is attached to the post, but no matter how I tried, it doesn’t work out for me. Question: How to do this?
Guys who know how to do, please help, I will be very grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Whikont, 2014-04-26
@Whikont

Как-то так:
$a = $wall[$i]->attachments[0]->photo->photo_604;
echo "<img src= '$a'>";
Это если прикреплена одна картинка. Если больше, то нужно будет менять индекс у «attachments[]» на 1,2,3,… для каждого следующего изображения

A
Akmal Sulaymonov, 2015-03-01
@akmalsulaymonov

and how all records are parsed?
How do I understand this to happen with the help of "offset" ?

$offs = 1440;  // Переменную в цикле уменьшаем на "-20"
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.7&filter=all&domain=opmus&offset={$offs}&count=50&extended=1"); // Отправляем запрос

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question