Download videos VK API?


define('VK_ACCESS_TOKEN', 'xyz token');
define('VK_API_VERSION', 5.103);

// // //
// Download the video from the external server to your server
// // //

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'techslides.com/demos/sample-videos/small.mp4');
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);

$curl_result = curl_exec($ch);

curl_close($ch);

// Put video in folder with script
$fp = fopen('small.mp4', 'x');
fwrite($fp, $curl_result);
fclose($fp);

// // //
// Get the address of the link where to download videos
// // //

$ch = curl_init();
$parameters = http_build_query([
'access_token' => VK_ACCESS_TOKEN, // access_token / key access
'v' => VK_API_VERSION, // API version
'name' => 'Name of video',
'description' => 'a Comprehensive description of our first videos.',
'group_id' => 192101047, // group ID
'no_comments' => 0 // allow commenting
]);

curl_setopt($ch, CURLOPT_URL, 'https://api.vk.com/method/video.save?' . $parameters);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$curl_result = json_decode(curl_exec($ch), TRUE); // convert JSON array which is returned to us VK, in regular PHP array

curl_close($ch);

// // //
// Uploading the video on server VK
// // //

$ch = curl_init();
$parameters = [ 'video_file' => new CURLFile('small.mp4') ];

curl_setopt($ch, CURLOPT_URL, $curl_result['response']['upload_url']);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, TRUE);

$curl_result = json_decode(curl_exec($ch), TRUE);

curl_close($ch);

if (isset($curl_result['error'])) {
exit('String' . __LINE__ . ': Error loading video onto servers VC: '. $curl_result['error'] . '.');
}

echo 'Video was successfully uploaded.';

Says Successfully loaded, and in the group not appearing
April 7th 20 at 15:31
1 answer
April 7th 20 at 15:33
Solution
Found a solution to the problem. Is using server regular Acces_token is blocked. Need when obtaining a token in scope to prescribe law&offline

Find more questions by tags APIPHPVKontakte