L
L
Laranessa2019-06-11 20:47:12
PHP
Laranessa, 2019-06-11 20:47:12

How to get hash of video object using VK Callback API?

Hello)
I'm trying to write a script that will generate an iframe (embed code) and write it to a file when a new video broadcast appears in VK in my group.
Here is the code:

<?php

//Строка для подтверждения адреса сервера из настроек Callback API 
$confirmation_token = 'токен подтвержденния'; 

//Ключ доступа сообщества 
$token = 'токен на управление сообществом'; 

//Получаем и декодируем уведомление 

$data = json_decode(file_get_contents('php://input')); 

if (($data->group_id != ид_группы) or ($data->secret != 'секретик)')) {
    echo "сюда нельзя!";
    exit;
}
//Проверяем, что находится в поле "type" 
switch ($data->type) { 
//Если это уведомление для подтверждения адреса... 
case 'confirmation': 
//...отправляем строку для подтверждения 
echo $confirmation_token; 
break; 

//Если это уведомление о новом видео... 
case 'video_new': 
$video_id = $data->object->id;
$video_owner_id = $data->object->owner_id;
$video_player = $data->object->player;
$videos = $video_owner_id . '_'.$video_id;
$iframe = <<<EO
<iframe src="https://vk.com/video_ext.php?oid=$video_owner_id&id=$video_id&hash=ВОТ_ТУТ_НУЖЕН_HASH" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>
EO;
if (isset($data->object->live)) { $video_live = $data->object->live; }

if ($video_live == 1) {
    file_put_contents('./frame.txt', $iframe);
}

//Возвращаем "ok" серверу Callback API 

echo('ok');
break;

}

exit;

I was able to get the video broadcast ID and the owner ID of the video (in this case it will always be my group ID).
At the same time, $data->object->player is missing, although according to the VK documentation this field should be.
As a result, how can I get the hash of the video object or a ready-made iframe (embed code) or the player field of the video object using the VK Callback API?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Dunkin, 2019-06-14
@Laranessa

something like this

$access_token = "Токен"

switch($data->type) {
case 'video_new': 
$video_id = $data->object->id;
$video_owner_id = $data->object->owner_id;
$videos = $video_owner_id . '_'.$video_id;

$videoInfo = file_get_contents("https://api.vk.com/method/video.get?videos={$videos}&count=1&extended=1&v=5.95&access_token={$access_token}");

$iframe = "<iframe src=\"{$videoInfo['response'][items][0]['player']}\" width="100%" height="100%" frameborder="0"  allowfullscreen></iframe>";

if (isset($data->object->live)) { $video_live = $data->object->live; }

if ($video_live == 1) {
    file_put_contents('./frame.txt', $iframe);
}
break;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question