Использую следующий код:
<?php
print_r(upload('tmp_img.jpg','токен');
function upload($img,$token) {
($getUploadServer = curl('https://api.vk.com/method/photos.getWallUploadServer?access_token='.$token));
($getUploadServer = json_decode($getUploadServer, true));
( $uploadUrl = $getUploadServer['response']['upload_url']);
( $uploadPhoto = curl($uploadUrl, array('photo' => '@'.$img)));
($uploadJson = json_decode($uploadPhoto, true));
($savePhoto = curl('https://api.vk.com/method/photos.saveWallPhoto?access_token='.$token.'&server='.$uploadJson['server'].'&photo='.$uploadJson['photo'].'&hash='.$uploadJson['hash']));
return $savePhoto;
}
function curl( $url, $post = null )
{
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
if($post != null)
{
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
}
$response = curl_exec( $ch );
curl_close( $ch );
return $response;
}
?>
В ответе получаю:
{"error":{"error_code":100,"error_msg":"One of the parameters specified was missing or invalid: photos_list is invalid","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"photos.saveWallPhoto"},{"key":"server","value":"623817"},{"key":"photo","value":"[]"},{"key":"hash","value":"hash"}]}}
Где ошибка? Файл tmp_img.jpg
существует.