Answer the question
In order to leave comments, you need to log in
How to output JSON API VK?
There is a code:
// Уведомления через ВК POST запросом
$url = 'https://api.vk.com/method/messages.send';
$params = array(
'user_ids' => $idadmins.''.$ownerId, // Кому отправляем
'title' => 'Новое сообщение: '.$admins['response'][0]['name'], // Заголовок
'message' => $message, // Что отправляем
'attachment' => $attachments, // Прикрепления
'access_token' => $tokengroup, // access_token
'v' => '5.67',
);
// В $result вернется id отправленного сообщения
$request = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)));
if (isset($request['error']['error_code'])) {
$errorcode = "<div class=\"alert alert-danger alert-dismissible\"> Ошибка при уведомлении сообщений. Не можем отправить без разрешения!</div>";
}
$request = json_decode(file_get_contents("https://api.vk.com/method/messages.send?user_ids={$ownerId}&title={$groupname}&message={$message}&attachment={$attachments}&access_token={$tokengroup}"),true);
Answer the question
In order to leave comments, you need to log in
Well... First, put the query result in a separate variable, put the json decode result in another separate variable, search for errors on it, and output the first variable that you still have a json string.
Or I didn't understand the question.
UPD: the author, you once have json. You need an array of objects, not json. Understand at least in terms for starters.
What's the problem then? With a get request, you provide an example wrapped in json_decode, so do the same with the result from the post request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question