Answer the question
In order to leave comments, you need to log in
Why does VK say when downloading an mp3 audio format that it needs to be converted to mp3?
Maybe someone had a similar trouble.
In general, I need to load some audio from my server via vk api. 90% of these audios are not sent, an error -2 is returned. (This, according to the docks, is supposedly a problem with the application, but even VK support says that everything is fine with the application).
And one of 10 applications is loaded, others are not. Mp3 audio format. I'm already loading the audio with my hands, to which VK says: "The audio recording could not be saved.
Try converting the MP3 file and upload it again."
Code (PHP when uploading from server)
private function getServerAddress()
{
$buildQuery = [
'access_token' => $this->apiKey,
'v' => '5.95'
];
$endpoint = 'https://api.vk.com/method/audio.getUploadServer?' . http_build_query($buildQuery);
$content = json_decode(file_get_contents($endpoint));
return $content->response->upload_url;
}
public function uploadToVKServer()
{
$address = $this->getServerAddress();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => new CURLFile(dirname(__FILE__) . '/calls/' . $this->callId . '.mp3', 'audio/mp3')]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
$dataToQuery = [
'server' => $data['server'],
'audio' => $data['audio'],
'hash' => $data['hash'],
'access_token' => $this->apiKey,
'v' => '5.95',
];
$content =
file_get_contents('https://api.vk.com/method/audio.save?' . http_build_query($dataToQuery));
$content = json_decode($content, true);
return 'audio' . $content['response']['owner_id'] . '_' . $content['response']['id'];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question