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