B
B
bozilly2015-07-19 00:59:33
PHP
bozilly, 2015-07-19 00:59:33

How to get video from VK?

So the user enters a link like
vk.com/videos100973593?z=video100973593_171060396%...
or
vk.com/video100973593_171060396
Okay, I'll get 100973593 and 171060396 with a regular program.
But to embed a video on the site, the following frame is used : ">frame>
I.e. you need to get the hash somehow :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Baha Rustamov, 2015-07-19
@by133312

Here's an example for you:

<? 
  $token = "Ваш access_token"; // access_token брал от сюда http://u.to/8nA8CA
  
  $video_id = "100973593_171060396";
  
  $videoGet = file_get_contents("https://api.vk.com/method/video.get?videos=".$video_id."&access_token=".$token);
  $json_video = json_decode($videoGet,1);
  
  Echo'<iframe src="'.$json_video["response"][1]["player"].'" width="853" height="480"  frameborder="0"></iframe>';
?>

S
Sergey Sergeev, 2015-07-19
@alokazay

Just parse sfw. There is a direct link in different resolutions. But the contact constantly bans ip, domains.
Here is an example of parsing without tokens.

$link = 'oid=134218719&id=168399790&hash=f721a4d8be925b49&hd=2';
// Далее идет магия по извлечению прямой ссылки с вконтакта
$val = $link;

$valex = explode('&', $val);

$oidexp = explode('=', $valex[0]);

if (!isset ($oidexp[1])) return Response::json(array('success' => "false", "message" => "error oidexp"), 200);
$oid = $oidexp[1];

$idexp = explode('=', $valex[1]);
if (!isset($idexp[1])) return Response::json(array('success' => "false", "message" => "error  idexp"), 200);


$id = $idexp[1];

$hashexp = explode('=', $valex[2]);
$hash = $hashexp[1];

$nameexp = explode('=', $valex[3]);
$name = $nameexp[1];


$page_up = file_get_contents('http://vk.com/video_ext.php?oid=' . $oid . '&id=' . $id . '&hash=' . $hash . '&hd=1');
preg_match('<param name="flashvars" value="(.*)">', $page_up, $matches);


if (count($matches) < 1) return Response::json(array('success' => "false", "message" => "error  matches"), 200);

$buf = $matches[1];

$res = array();

foreach (explode('&amp;', $buf) as $tmp) {
    $tmp2 = explode('=', $tmp);
    $key = $tmp2[0];
    unset ($tmp2[0]);
    $res[$key] = implode('=', $tmp2);
}

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question