Wrote a PHP handler that creates posts in the group. But the question was how to post a picture? I tried to add a link to the attachments , but displays a link to the picture, but does not add the picture itself (which is located on this link). How can this be fixed?

 if( isset( $_POST['send'] ) ){ $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $hour = $_POST['hour']; $minute = $_POST['minute']; $photo = $_POST['link']; //тут хранится ссылка на картинку $senddate = $year."-".$month."-".$day." ".$hour.":".$minute.":00"; $date = strtotime($senddate); $url = 'https://api.vk.com/method/wall.post?owner_id=-137337424&attachments='.$photo.'&publish_date='.$date.'&v=5.63&access_token=мойтокен'; echo '<iframe src="'.$url.'" width="400px" height="50px"></iframe>'; echo "Выполнено"; 

  • Read the documentation - andreymal
  • @andreymal in the documentation there is no description of the cases of adding a picture by reference. Or am I just completely fail to understand something in the subtleties of the written documentation - NTP
  • So such a case is unavailable) Fill the pictures as described in the documentation and in the answer - andreymal

1 answer 1

Before you post to the wall, you must separately upload the published image and save it.

We get the download address using the request to the address: https://api.vk.com/method/photos.getWallUploadServer?access_token={your_access_token}&group_id={your_wall_id} As a result, the answer should come with the parameter upload_url - photo upload address.

We load and save photos on the server Vkontakte:

We send the file to the specified address. You can do this: curl -X POST -F 'photo=@/var/www/myphoto.jpg' '{upload_url}' or with the help of the CURL module for php . If the download is successful, you will receive a response with the parameters ( server, hash, photo ), which you need to send in the following request to save the photo: https://api.vk.com/method/photos.saveWallPhoto?access_token={your_access_token}&group_id={your_wall_id}&server={server}&photo={photo}&hash={hash}

We receive the answer with the id parameter - ID of the loaded image. We form the value of the photo parameter in the field attachments = photo{your_wall_id}_{photo_id} , where photo_id is the id downloaded image in the previous step.

copy-paste from http://blog.yamaker.ru/6-polnocennyy-avtoposting-v-gruppu-vkontakte-s-pomoschyu-api.html