Hello, SW. users! I am trying to get information about the mp3 file on the server vk.com, but in response it gives an HTTP / 1.1 404 Not Found error

Code:

<?php $file_url = 'http://cs4883.userapi.com/u92342187/audios/15012c2aac27.mp3'; $info = get_headers($file_url,1); print_r($info); 

Has anyone come across?

PS does not work with a working link to the file.

Returns:

 Array ( [0] => HTTP/1.1 404 Not Found [Server] => nginx/1.2.1 [Date] => Thu, 08 Nov 2012 21:30:33 GMT [Content-Type] => text/html [Content-Length] => 403 [Connection] => close ) 

It works fine on denver ..


SOLVED. As requested:

 <?php /** * Класс для работы с VK API * Класс видоизменен. Первоначальный вид и ссылка на автора класса: * http://a-panov.ru/2011/10/%D0%BA%D0%BB%D0%B0%D1%81%D1%81-%D0%B4%D0%BB%D1%8F-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D1%8B-vkontakte-api-php/ */ class vk { public static $error = ''; /** * Основной метод для запроса данных * * @param $method string имя метода api * @param $method array дополнительные параметры api * @return array результат запроса или FALSE при ошибке */ static function get($account = array(), $method, $params = array()) { if (empty($method)) { self::$error = 'Не задан метод'; return FALSE; } else { // обнулить статус ошибки self::$error = ''; } $params['api_id'] = $account['id_api']; $params['method'] = $method; // версия API if (empty($params['v'])) $params['v'] = '2.0'; // упорядочить ключи по алфавиту ksort($params); // сформировать список значений вида key=value $datas = array(); $strdatas = $account['user_id']; foreach ($params as $k => $v) { $strdatas .= $k . '=' . $v; $datas[] = $k . '=' . urlencode($v); } // формирование подписи $sig = md5($strdatas . $account['key']); // полная строка запроса к API $url = 'http://api.vk.com/api.php' . '?' . implode('&', $datas) . '&sig=' . $sig; // получить результат $result = file_get_contents($url); if ($result) { // удалить ненужные символы $result = preg_replace('![\\x00-\\x1f]!', '', $result); // преобразовать json-строку в массив $arr = new SimpleXMLElement($result); // при наличии ошибка if (isset($arr['error'])) { // записать её текст self::$error = 'Ошибка: ' . $arr['error']['error_msg'] . ' (' . $arr['error']['error_code'] . ')'; $arr = FALSE; } } else { $arr = FALSE; self::$error = 'Нет доступа к адресу ' . 'http://api.vk.com/api.php'; } return $arr; } } /** * Настройки приложения */ $key_app = 'kjlsdhglsdhg'; // Ключ приложения $user_id = 778787878; // Ид создателя $api_id = 454545454545; // ID приложения $method = 'audio.getById'; // метод /** * Получение информации */ $params = array(); $params['audios'] = '41589363_104634384'; $params['test_mode'] = 1; $mp3 = vk::get(array( 'key' => $key_app, 'user_id' => $user_id, 'id_api' => $api_id), $method, $params); if (FALSE === $mp3) { exit ('Error'); } else { /** * Получаем заголовки файла */ $get = get_headers($mp3->audio->url, 1); print_r($get); } 
  • I was looking for the author, just found the link - iNeeXT

2 answers 2

For each user, the link to the file is unique. Before you get the link, you must log in. Naturally, the browser and php are different users. Or you must mimic the browser through headers / curl.

  • Understood thanks. You can do this with the VK API, right? - iNeeXT
  • Yes, but here the server part is relegated to the background, because All requests will be executed like this: client <-> VK. The client is a browser, in the role of "executing commands" JavaScript. API in fact is not difficult, but I had to tinker with the docks. - lampa
  • I use API without javascript, i.e. connection to the application vk. This scheme should work: connect to the VC application> send the request using the audio.getById method and get the link> get the file information - iNeeXT
  • HM interesting! It would be nice if you wrote a working example and updated the post. You look, someone will definitely come in handy. - lampa
  • Well =) I'll finish it and post it in the post. - iNeeXT

a similar link in the one-time contact, open it in the browser and see for yourself

  • I wrote in the question "PS does not work even with a working link to the file." - iNeeXT