Answer the question
In order to leave comments, you need to log in
VK api, photos are not uploaded to the server?
//декодирую адрес картинки
$image_url = urlencode($image_url);
$response = 'https://api.vkontakte.ru/method/photos.getWallUploadServer?owner_id='.$group_id.'&access_token='.$access_token;
//получаю URL для загрузки на сервер
$response = @file_get_contents($response);
$response = json_decode($response);
$upload_url = $response->response->upload_url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file1' => $image_url));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data; charset=UTF-8'));
$otvet = curl_exec($ch);
curl_close($ch);
$otvet = json_decode($otvet);
print_r($otvet);
[server] => 630317 [photo] => [] [hash] => 78730dd19f6e53a70b7f54fbb7803519
Answer the question
In order to leave comments, you need to log in
For some reason, you are transferring the encoded address of the image to VK. But you must transfer the file itself. You must upload the image to the server and then rewrite the line
so if you have PHP less than 5.5:
or if PHP is greater than or equal to 5.5:
This line can be removed:
Also, use the api.vk.com domain to access the API and don't forget to pass the API version in the v parameter in your requests .
UPD: also, as noted earlier, to upload photos to the wall, you must pass photos in the photo field , not file{...}.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question